Thanks ... it runs , but as mentioned it has some side effects.... even if I cannot have one side wo the other one ... learn a lot about collateral effects...
On Dec 1, 11:29 pm, Rob Biedenharn <[email protected]> wrote: > On Dec 1, 2011, at 5:01 PM, Everaldo Gomes wrote: > > > > > > > > > > > I think it's fine. > > > Best Regards, > > Everaldo > > > On Thu, Dec 1, 2011 at 7:59 PM, Erwin <[email protected]> wrote: > > Is it wrong to use a beings_to on both side of a one-to-one > > association ? > > > User > > belongs_to :account so I have an account_id field > > > Account > > belongs_to :owner, :class_name => 'User', :foreign_key => 'user_id' > > > I can get user.account and account.owner > > It runs, but I wonder about any collateral effect... > > > thanks for your feedback > > Which one do you create first? What foreign key value does it get? Do > you always do the create/create/update in a transaction? > > Do you ever (ever!) have one without the other? > > class User < ActiveRecord::Base > has_one :account > end > > class Account < ActiveRecord::Base > belongs_to :owner, :class_name => 'User', :foreign_key => 'user_id' > end > > I think that current versions of ActiveRecord have the right default > for the foreign key (which is the _id after the class name rather than > the association name), but specifying it works just fine, of course. > > -Rob > > Rob Biedenharn > [email protected] http://AgileConsultingLLC.com/ > [email protected] http://GaslightSoftware.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 [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.

