Taylor Strait
2006-Oct-29 00:52 UTC
how to create 0:M or 0:1 relationships in ActiveRecord?
I''m comfortable using has_many and belongs_to for 1:M relationships. But how do you implement 0:1 and 0:M relationships? Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jake Janovetz
2006-Oct-29 06:32 UTC
Re: how to create 0:M or 0:1 relationships in ActiveRecord?
Taylor Strait wrote:> I''m comfortable using has_many and belongs_to for 1:M relationships. > But how do you implement 0:1 and 0:M relationships? Thanks!What does that mean? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Taylor Strait
2006-Oct-29 06:38 UTC
Re: how to create 0:M or 0:1 relationships in ActiveRecord?
Maybe a better question is, "Can Active Record use :has_many and :belongs to without FK definitions being present in the database?" For example, I have buildings who have landlords. However, since this data is input by renters, landlord data will often not be submitted. So i need to indicate that builds belong to landlords but AR complains when there is no landlord to attribute it to. If I remove the foreign key constraint how do I define the relationship? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jake Janovetz
2006-Oct-29 07:41 UTC
Re: how to create 0:M or 0:1 relationships in ActiveRecord?
Taylor Strait wrote:> Maybe a better question is, "Can Active Record use :has_many and > :belongs to without FK definitions being present in the database?" > > For example, I have buildings who have landlords. However, since this > data is input by renters, landlord data will often not be submitted. So > i need to indicate that builds belong to landlords but AR complains when > there is no landlord to attribute it to. If I remove the foreign key > constraint how do I define the relationship?You''re certainly allowed to have a :belongs_to relationship to nil. i.e., create a building such that building.landlord_id=nil. Just don''t "validates_presence_of" on landlord_id. Jake -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---