Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

has_many :through in fixtures in rails 3.1

I want to set up some has_many, :through objects using fixtures for testing in rails 3.1.

If you look at the documentation on the association as an example, I want to know how to assign assemblies to parts. The only way I've found to do it is to explicitly create the manifest object in it's own file, but if I'm happy with the defaults on that model and all I want to specify are the part/assembly id's then is there a way to do it directly?

http://guides.rubyonrails.org/association_basics.html#choosing-between-has_many-through-and-has_and_belongs_to_many

I want something like:

my_assembly:
    parts: my_first_part, my_second_part

This works if you do HABTM, but not when you have the explicit join model.

like image 291
spike Avatar asked Nov 27 '22 20:11

spike


1 Answers

Assuming you want or have to stick with fixtures, then if you switch from an HABTM to a has_many :through relationship, then you can no longer use the short inline lists. You must create a separate fixture file for the :through model.

like image 89
rwc9u Avatar answered Feb 20 '23 00:02

rwc9u