view · edit · sidebar · attach · print · history

Named Access in ODBA

<< TransactionRollback | Index | >>

 require 'odba'

 class Recursive
   include ODBA::Persistable
   attr_accessor :child
   def last_offspring
     if(@child)
       @child.last_offspring
     else
       self
     end
   end
   def generations
     if(@child)
       1 + @child.generations
     else
       1
     end
   end
 end

 ODBA.storage.dbi = DBI.connect('DBI:pg:test', 'hwyss', '')

 root = ODBA.cache.fetch_named('recursion-root', self) { 
   Recursive.new
 }

 generation_x = root.last_offspring 
 generation_x.child = Recursive.new
 generation_x.odba_store

 root.generations

every time this is run, generations will increase by one

view · edit · sidebar · attach · print · history
Page last modified on March 15, 2011, at 09:53 AM