populator icon indicating copy to clipboard operation
populator copied to clipboard

Support HABTM

Open ryanb opened this issue 15 years ago • 2 comments

Currently there is no way to populate has_and_belongs_to_many because there is no model set apart for the join table. There should be additional methods one can call on either side of the association to setup the join.

ryanb avatar Jul 01 '09 16:07 ryanb

really need this... I thought it might be possible by populating the join table separately... But I can't even figure out how to populate a table with no "id" field.... I get this error when I tried to do that... Mysql2::Error: Unknown column 'id' in 'field list': SELECT id FROM roles_users ORDER BY id DESC

ipranay avatar Jan 15 '11 06:01 ipranay

I am populating a join table by joining with one table as seen in your example and then using a random function to generate id's for the other table. It's not perfect but I need a lot of data to test with and this at least fills up the db. To populate a table with no 'id' field I wrote a rescue block around the last_id_in_database function (factory.rb line 75). The populate then works as expected as the id field is not needed to populate the data. I would much prefer a nicer method though Ryan.

JonathanKnight avatar Feb 10 '11 13:02 JonathanKnight