[Nitro] Og create method

Jonathan Buch john at oxyliquit.de
Mon Aug 20 06:52:08 EDT 2007


> It seems to be that line calling #create, mixed with this initialization:
> belongs_to :account, Account
> class Character
> 	def initialize(name = nil, acc = nil)
> 		super(name)
> 		self.account = acc # this is what's producing the error
> 	end
> end

ahhh yes, you actually can't do this exactly.  This is setting a relation.
Setting a relation means (DB wise) that there must already be objects present
too relate to (meaning the character must have a primary key already which
also will go into acc.character_oid.

Now, this is the point where I'm supposed to make a suggestion on how else
to do this.  ;)

     class Account
       has_one Character

     class Character
       belongs_to Account

       def initilize(name)

     a1 = Account.new
     c1 = (a1.character = Character.new)

With the current Og autosaving scheme, this will create 2 objects refering
to each other and saved to the DB already.  (If not, then the current
official 'og/relation/refers_to.rb' differs from mine in that account).

Hope that helps,


Feel the love

More information about the Nitro-general mailing list