Comments (10)
Doesn't it already work?
from factory-girl.
Maybe provide an example
from factory-girl.
factory.define('variant', Variant, {
'quantity': function () {
return faker.random.number(1, 10)
},
'colour': function () {
return factory.assoc('colour', 'product_colour_id'),
}
'size': function () {
return factory.assoc('size', 'product_size_id')
}
})
from factory-girl.
That should be:
factory.define('variant', Variant, {
quantity: faker.random.number.bind(faker, 1, 10)
colour: factory.assoc('colour', 'product_colour_id'),
size: factory.assoc('size', 'product_size_id')
});
from factory-girl.
Its trying to set the a colour column and size column on the variant table, rather then product_colour_id & product_size_id columns?
from factory-girl.
Right, you should omit the second parameter in the call to .assoc()
, then it will return the object and Bookshelf should be happy.
factory.define('variant', Variant, {
quantity: faker.random.number.bind(faker, 1, 10)
colour: factory.assoc('colour'),
size: factory.assoc('size')
});
from factory-girl.
It tries to insert it as an object,
TypeError: insert into `variants` (`colour`, `created_at`, `quantity`, `size`, `updated_at`) values ('{\"colour\":\"ivory\",\"swatch\":\"000000\",\"updated_at\":\"2015-08-17T01:15:36.442Z\",\"created_at\":\"2015-08-17T01:15:36.442Z\",\"id\":16}', '2015-08-17 01:15:36.809', 0, '{\"size\":\"XL\",\"updated_at\":\"2015-08-17T01:15:36.553Z\",\"created_at\":\"2015-08-17T01:15:36.553Z\",\"id\":16}', '2015-08-17 01:15:36.809') - undefined is not a function
from factory-girl.
Right okay, you need to use factory.assoc('colour', 'id')
. I've updated the README and added a test for this. Let me know if that doesn't work for you.
from factory-girl.
Yeah sorry was just confusing that its actually using the id rather then the asociation_name. Any way to support the association name, rather then name_id also any way to support association types, hasOne etc, perhaps using some sort of reflection? This would make it super easy to use with bookshelf.
from factory-girl.
The adapter layer is pretty simple, so that's not supported at this stage. I'm open to pull requests though if that's of value to you.
from factory-girl.
Related Issues (20)
- Expose passed attrs to initializer function HOT 1
- concatonating values from chance generator
- Add to CHANGELOG that `buildSync` is gone in v4
- factory.assoc is not taking attributes values from factory.create
- Resetting Sequence HOT 1
- UnhandledPromiseRejectionWarning: TypeError: Model is not a constructor
- ENHANCEMENT: Async buildOptions on extended factory not taking the base factory values HOT 1
- afterCreate() in Sub-Object Creates Weird Error HOT 1
- make compatible mongoose 5.29 populate
- TypeScript definition HOT 5
- Calling create "hangs" during create
- Is this project still maintained? HOT 7
- Undefined attribute on initializer cause error HOT 1
- How to define @many to many ? HOT 1
- delete objects after test suite HOT 3
- Is it possible to use build options with an extended factory? HOT 1
- Invalid params when callback afterBuild and afterCreate in case create/buildMany
- How to use a factory definition in a separate file? HOT 1
- When using factory with jest and mongoose, process doesn't end HOT 1
- [DEP0128] DeprecationWarning: Invalid 'main' field HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from factory-girl.