This repository was archived by the owner on Aug 18, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import set from 'lodash/set.js'
2+ import { OPTIONS } from '../symbols.mjs'
23
34/**
45 * An instance of a single fixture which represents a single
@@ -44,8 +45,9 @@ class Fixture {
4445 set ( model , relations , insertMap ) {
4546 for ( const [ key , pointer ] of Object . entries ( relations ) ) {
4647 const relation = insertMap . get ( pointer )
48+ const { col } = relation [ OPTIONS ] . table . pk
4749
48- set ( model , key , relation [ relation . _options . table . pk ] )
50+ set ( model , key , relation [ col ] )
4951 }
5052 }
5153}
Original file line number Diff line number Diff line change 11import { uuid } from '../utils.mjs'
2+ import { OPTIONS } from '../symbols.mjs'
23
34export const NOW = new Date ( ) . toISOString ( )
45
@@ -20,7 +21,7 @@ class Model {
2021
2122 this . #configure( table )
2223
23- this [ options . keys . options ] = {
24+ this [ OPTIONS ] = {
2425 ...options ,
2526 table
2627 }
Original file line number Diff line number Diff line change 1- import omit from 'lodash/omit.js'
21import invokeMap from 'lodash/invokeMap.js'
32import { filterValues } from '../utils.mjs'
3+ import { OPTIONS } from '../symbols.mjs'
44import Model from './model.mjs'
55import Table from './table.mjs'
66
@@ -76,8 +76,7 @@ class Resolver {
7676 * @returns {object } - Collection of relations to resolve later.
7777 */
7878 relations ( model ) {
79- const json = omit ( model , [ this . options . keys . options ] )
80- const relations = filterValues ( json , v => v ?. toString ( ) . match ( / ^ @ [ \w ] + / g) )
79+ const relations = filterValues ( model , v => v ?. toString ( ) . match ( / ^ @ [ \w ] + / g) )
8180
8281 this . applyPolymorphism ( model , relations )
8382
@@ -97,7 +96,7 @@ class Resolver {
9796 table : { columns } ,
9897 suffixes : { type, id } ,
9998 fixtures
100- } = model . _options
99+ } = model [ OPTIONS ]
101100
102101 for ( const [ polyName , relationKey ] of entries ( relations ) ) {
103102 const polyType = polyName + type
Original file line number Diff line number Diff line change 1+ export const OPTIONS = Symbol ( 'options' )
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import isPlainObject from 'lodash/isPlainObject.js'
22import isArray from 'lodash/isArray.js'
33import debug from 'debug'
44import * as uuidLib from 'uuid'
5+ import { OPTIONS } from './symbols.mjs'
56
67const {
78 keys,
@@ -25,7 +26,7 @@ export const uuid = uuidLib.default?.v4 ?? uuidLib.v4
2526 */
2627export function toJson ( instance ) {
2728 const modelMap = keys ( instance )
28- . filter ( key => ! ! instance . _options . table . columns [ key ] )
29+ . filter ( key => ! ! instance [ OPTIONS ] . table . columns [ key ] )
2930 . map ( key => {
3031 const cell = instance [ key ]
3132 const isJson = isPlainObject ( cell ) || isArray ( cell )
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ import Resolver from './lib/resolver.mjs'
1414 * @property {string } [type] - Primary key column type.
1515 * @property {string } directory - Path to fixture files.
1616 * @property {object } keys - Configurable keys for storing options relating to this program.
17- * @property {string } keys.options - Key to use on Model instances for options.
1817 * @property {string } keys.model - Key to use for model options within the fixtures.
1918 * @property {object } suffixes - Polymorphic column suffixes.
2019 * @property {string } suffixes.type - Suffix used for the polymorphic type column.
@@ -31,7 +30,6 @@ export const DEFAULT_OPTIONS = {
3130 type : 'uuid'
3231 } ,
3332 keys : {
34- options : '_options' ,
3533 model : '_model'
3634 } ,
3735 suffixes : {
You can’t perform that action at this time.
0 commit comments