Hello fellow Railers, I wonder if somebody implemented such behaviour already: maria.friend = peter and then automatically this would happen with peter peter.friend = maria Similar: maria.friend = nil would set whatever maria.friend was before to nil too, so: peter.friend = nil Does anybody know how I could extend has_one to such has_only_one behaviour? Thanks, folks! Phil -- 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 -~----------~----~----~----~------~----~------~--~---
has_one means that the entity has 0 or 1. It is a "has only one." It looks like you''re trying a self-referencing relationship. Make sure the Person (assuming) model has both has_one and belongs_to methods. Something like: has_one :friend, :class => ''Person'' belongs_to :person On 10/11/06, PhilK <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hello fellow Railers, > > I wonder if somebody implemented such behaviour already: > > maria.friend = peter > > > and then automatically this would happen with peter > > peter.friend = maria > > > Similar: > > maria.friend = nil > > would set whatever maria.friend was before to nil too, so: > peter.friend = nil > > Does anybody know how I could extend has_one to such has_only_one > behaviour? > > Thanks, folks! > Phil > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Oops... has_one :friend, :class => ''Person'' belongs_to :person, :foreign_key => ''friend'' On 10/12/06, Derek Perrault <derek.perrault-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > has_one means that the entity has 0 or 1. It is a "has only one." > > It looks like you''re trying a self-referencing relationship. Make sure > the Person (assuming) model has both has_one and belongs_to methods. > > Something like: > > has_one :friend, :class => ''Person'' > belongs_to :person > > On 10/11/06, PhilK < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > > > Hello fellow Railers, > > > > I wonder if somebody implemented such behaviour already: > > > > maria.friend = peter > > > > > > and then automatically this would happen with peter > > > > peter.friend = maria > > > > > > Similar: > > > > maria.friend = nil > > > > would set whatever maria.friend was before to nil too, so: > > peter.friend = nil > > > > Does anybody know how I could extend has_one to such has_only_one > > behaviour? > > > > Thanks, folks! > > Phil > > > > -- > > 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 -~----------~----~----~----~------~----~------~--~---
Derek Perrault wrote:> Oops... > > has_one :friend, :class => ''Person'' > belongs_to :person, :foreign_key => ''friend''I will try this, thanks Derek! -- 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 -~----------~----~----~----~------~----~------~--~---