On Apr 30, 2009, at 1:29 PM, serenobs wrote: > > thanks for replies. > it gives me some thought about making active record association. > > then what if the man is a single? > husband may not have current_marriage. > i was thinking that has_one means it should have one object. > But as you know not every man will marry. > > please more advice for this novice.
Then, man.current_marriage will be nil as will man.wife has_one really defines a 0/1 and has_many a 0/n relation. -Rob > > > > On May 1, 2:17 am, Rob Biedenharn <[email protected]> wrote: >> On Apr 30, 2009, at 12:56 PM, Commander Johnson wrote: >> >>> Did you consider >> >>> has_one :wife >> >>> And in Wife.rb >> >>> belongs_to :man >> >> Or: >> class Wife >> has_many :marriages >> has_one :current_marriage, :class_name => 'Marriage', :conditions >> => { :current => true } >> has_one :husband, :through => :current_marriage >> end >> >> class Marriage >> belongs_to :wife >> belongs_to :husband >> end >> >> class Husband >> has_many :marriages >> has_one :current_marriage, :class_name => 'Marriage', :conditions >> => { :current => true } >> has_one :wife, :through => :current_marriage >> end >> >> -Rob >> >> Rob Biedenharn http://agileconsultingllc.com >> [email protected] >> >> >> >>> On Thu, Apr 30, 2009 at 6:49 PM, serenobs <[email protected]> >>> wrote: >> >>> (my post was deleted i don't know why) >>> Hi. I have a question. >>> for example, when model records about man, suppose man can marry >>> with >>> 1 woman. >>> then i think code will be like this >>> class Man < ActiveRecord::Base >>> has_many: wife >>> end >> >>> Because one man can marry with up to 1 woman( 0 or 1 ) >>> it can't be 1:1 relationship, didn't it? >>> but at the same time more than 1 wife is not allowed. >>> then how can i model this relationship into rails code? >>> has_many :limit option is fit for this relation? >> >>> Thanks. >>> and i wish it is not deleted again. If it should be deleted please >>> let >>> me know why it should be.- Hide quoted text - >> >> - Show quoted text - > > --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

