Giter Site home page Giter Site logo

Comments (10)

simonexmachina avatar simonexmachina commented on September 25, 2024

Doesn't it already work?

from factory-girl.

simonexmachina avatar simonexmachina commented on September 25, 2024

Maybe provide an example

from factory-girl.

whatyoubendoing avatar whatyoubendoing commented on September 25, 2024
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.

simonexmachina avatar simonexmachina commented on September 25, 2024

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.

whatyoubendoing avatar whatyoubendoing commented on September 25, 2024

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.

simonexmachina avatar simonexmachina commented on September 25, 2024

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.

whatyoubendoing avatar whatyoubendoing commented on September 25, 2024

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.

simonexmachina avatar simonexmachina commented on September 25, 2024

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.

whatyoubendoing avatar whatyoubendoing commented on September 25, 2024

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.

simonexmachina avatar simonexmachina commented on September 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.