Hello, I have the following scenario: class User; has_and_belongs_to_many :roles; end class Role; has_and_belongs_to_many :users; end #roles schema only has name (string) as attribute an additional table ''roles_users'' with user_id (integer) and role_id (integer) was necessary. Then I created a fixture in users.yml: admin: roles: admin, guest and in roles.yml: guest: name: guest admin: name: admin This should work as mentioned in the docs: http://api.rubyonrails.org/classes/Fixtures.html But the following line did not pass: assert_not_nil users(:admin).roles.find_by_name(''admin'') Because users(:admin).roles is empty! For the problem I crawled a lot of docs but I cannot see where I made a mistake. Could someone lead me in the right direction? Regards, Peter. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter
2008-Nov-23 22:22 UTC
Re: Cannot get fixtures working (with has_and_belongs_to_many)
Hmmh, even after cleaning up the roles_users (without timestamp) it does not work (Hint from [1]) Tried out different order of fixture importing -> nothing helps. So, I switched to the old way to define fixtures [2] and it works :-) Regards, Peter. [1] http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/ea4de9d194fefc2d/62cd3b8f365eba8b [2] http://railsforum.com/viewtopic.php?id=50 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2008-Nov-23 22:46 UTC
Re: Cannot get fixtures working (with has_and_belongs_to_many)
On Nov 23, 2008, at 5:22 PM, Peter wrote:> > Hmmh, > > even after cleaning up the roles_users (without timestamp) it does not > work (Hint from [1]) > Tried out different order of fixture importing -> nothing helps. > > So, I switched to the old way to define fixtures [2] and it works :-) > > Regards, > Peter. > > [1] > http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/ea4de9d194fefc2d/62cd3b8f365eba8b > [2] > http://railsforum.com/viewtopic.php?id=50This is the only message I''ve looked at, but can you turn the join table''s fixture into an ordered map: --- !omap - first: id: "1" role_id: "1" user_id: "1" - second: id: "2" role_id: "1" user_id: "2" -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter
2008-Nov-26 07:56 UTC
Re: Cannot get fixtures working (with has_and_belongs_to_many)
Thanks for the answer Rob! The intention was to avoid the the explicit definition of a join table in the fixtures, like it is possible since some months. See ''Let‘s make the HABTM fixture go away. '' in http://api.rubyonrails.org/classes/Fixtures.html For your approach: I will put the omap into a roles_users.yml file, right? Regards, Peter. On Nov 23, 11:46 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Nov 23, 2008, at 5:22 PM, Peter wrote: > > > > > > > Hmmh, > > > even after cleaning up the roles_users (without timestamp) it does not > > work (Hint from [1]) > > Tried out different order of fixture importing -> nothing helps. > > > So, I switched to the old way to define fixtures [2] and it works :-) > > > Regards, > > Peter. > > > [1] > >http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/... > > [2] > >http://railsforum.com/viewtopic.php?id=50 > > This is the only message I''ve looked at, but can you turn the join > table''s fixture into an ordered map: > > --- !omap > - first: > id: "1" > role_id: "1" > user_id: "1" > - second: > id: "2" > role_id: "1" > user_id: "2" > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2008-Nov-26 14:46 UTC
Re: Cannot get fixtures working (with has_and_belongs_to_many)
On Nov 26, 2008, at 2:56 AM, Peter wrote:> Thanks for the answer Rob! > The intention was to avoid the the explicit definition of a join table > in the fixtures, > like it is possible since some months. See ''Let‘s make the HABTM > fixture go away. '' in > http://api.rubyonrails.org/classes/Fixtures.htmlHadn''t seen that. (But I haven''t used a HABTM association in a while either.)> > > For your approach: I will put the omap into a roles_users.yml file, > right? > > Regards, > Peter.Yes, that''s right. I noticed that the "YAML Fixtures" section of that page you referenced describes the omap type also. -Rob> > > On Nov 23, 11:46 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > wrote: >> On Nov 23, 2008, at 5:22 PM, Peter wrote: >> >> >> >> >> >>> Hmmh, >> >>> even after cleaning up the roles_users (without timestamp) it does >>> not >>> work (Hint from [1]) >>> Tried out different order of fixture importing -> nothing helps. >> >>> So, I switched to the old way to define fixtures [2] and it >>> works :-) >> >>> Regards, >>> Peter. >> >>> [1] >>> http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/ >>> ... >>> [2] >>> http://railsforum.com/viewtopic.php?id=50 >> >> This is the only message I''ve looked at, but can you turn the join >> table''s fixture into an ordered map: >> >> --- !omap >> - first: >> id: "1" >> role_id: "1" >> user_id: "1" >> - second: >> id: "2" >> role_id: "1" >> user_id: "2" >> >> -Rob >> >> Rob Biedenharn http://agileconsultingllc.com >> R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---