[Nitro] Og and legacy tables

Jonathan Buch john at oxyliquit.de
Mon May 21 06:12:47 EDT 2007


Hi,

just a quick reply.

> But often it's necessary to work with pre-existing tables from another  
> application, and in those cases, ActiveRecord adapts pretty well -- you  
> can specify join table names ( e.g., :through ), override default table  
> names and unique id field names, etc.

Og does adapts pretty well here too:

You just have to model the Og classes after the real tables and adapt:

class OgModel
   # To use a different pk
   attr_accessor :id, Fixnum, :primary_key => true

   # custom join tables
   joins_many :pictures, Picture, :through => ModelPics
end

class ModelPics
   # set the sql table
   set_sql_table "join_table_foo"

   # has_ones are needed to generate the correct relations

   # for example specify a special foreign key
   has_one OgModel, :foreign_key => 'to_model'
   has_one Picture
end

class Picture

end

Hope that makes you happy!

Also see the test::unit regarding custom primary keys and
http://oxyliquit.de/question/94 for a quick overview.

Jo

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


More information about the Nitro-general mailing list