[Nitro] The has_one/belongs_to relationship

Matthew B Gardner weather at speakeasy.net
Sat Aug 18 11:59:06 EDT 2007

Thank you for the response -- it's still not working, so I'll post the output 
from the additions you suggested.

> When I try to assign the created character to Account#character,
> however, it treats the character variable as a local variable. For instance,
>> in Account:
>>character = Character.create msg.capitalize, self
>> save!

>I assume this is within a method in the Account# scope?

Yes, this is in an Account method.

>> Checking character outside of that method returns nil, and the 
>> database field is NULL. I tried using self.character and experienced the 
>> results.

>the Account#character= method is defined by Og and handles the rel saving.

>self.character = Character.create()
>p @character, @character_oid
># save!
>update(:only => [:character_oid]) # slight optimization

p @character #=> nil
p @character_oid #=> 5
update(:only => [:character_oid]) # slight optimization #=> 07-08-18 11:42:07 
[ERROR] (Account) Account#update unknown message - {:only=>[:character_oid]}

Despite the error message, it does setup its @character_oid in the database, 
but you can see that @character is still nil. Also, the corresponding 
Character isn't loaded and attached when the Account object is loaded from 
the database -- my has_many/belongs_to relationship does this (and rather 
beautifully, I might add) -- should I expect the same from this relationship?

Thank you for any assistance you can offer,

More information about the Nitro-general mailing list