[Nitro] The has_one/belongs_to relationship

Jonathan Buch john at oxyliquit.de
Sun Aug 19 14:42:11 EDT 2007


Hi,

> I may have spoken a little prematurely on this -- I am encountering a problem.
> When I call Character#create, or when a Character object is loaded (via it's
> corresponding Account being loaded), it's creating it's own account. To
> illustrate, this is what's happening:
>
> a1 = Account.new
> a1.character = Character.create self
> a1.equal?(a1.character.account) #=> false
>
> The same thing is happening when loaded from the database, so the account is
> pointing to the character, but the character is pointing to a different
> account (an account with the same attributes, but a different identity).

Yes, a different 'identity', but not 'equality', depending on which method is
called.  ;)
Ruby knows .eql? .equal? .== .===
.equal? is for testing if the object ids are the same, which they are not in
this case.

a1 == a1.character.account # true

Og overrides ==() to react on the primary key of that model.

> I'm assuming I'm doing this to myself, here is how I'm initializing Character:

Looks all good.  :)

> Let me know if that isn't enough information, or if it's unclear.

> Thanks for any help (getting closer!),

You're welcome.  :)

Jo

-- 
Feel the love
http://pinkjuice.com/pics/ruby.png


More information about the Nitro-general mailing list