Hi all, I am a newbie in ruby/rails. I have a question about my database model: table1: entities (name, description, author_id ...) table2: relations (source_id, target_id, relation_type) (it describes the relations between 2 entities and the relation type) How can I define models using rails, or do I need to redefine my database schema? thank you -- Posted via http://www.ruby-forum.com/.
On Jul 20, 2006, at 2:21 PM, Andy Gao wrote:> Hi all, > > I am a newbie in ruby/rails. > > I have a question about my database model: > table1: entities (name, description, author_id ...) > table2: relations (source_id, target_id, relation_type) (it describes > the relations between 2 entities and the relation type) > > How can I define models using rails, or do I need to redefine my > database schema? > > thank you > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsI''m slightly confused about what you''re trying to do. Regardless, it sounds like you''re looking for has_many, belongs_to, etc. Those are the active record commands that allow you to make relationships between tables. If that sounds like what you want, then go check them out in Agile Rails book. -Ben Lisbakken
Ben Lisbakken wrote:> I''m slightly confused about what you''re trying to do. Regardless, it > sounds like you''re looking for has_many, belongs_to, etc. Those are > the active record commands that allow you to make relationships > between tables. If that sounds like what you want, then go check > them out in Agile Rails book. > > -Ben LisbakkenThe relation table describe the relationship between 2 entities in entity table. So as you say, in entity model: has_and_belongs_to_many :entity How can I define the relation table? As far as I know, the relation table name will be "entities_entities"? and how can I define name of the table columns (the entity_ids) ? Thank you for your quick response, Ben. -- Posted via http://www.ruby-forum.com/.
Seemingly Similar Threads
- NameError when trying to combine Recipe 14 (rich HABTM) & Rec. 10 (self-ref HABTM):
- rake aborted! can't convert Hash into String
- [PATCH] IOMMU: don't disable bus mastering on faults for devices used by Xen or Dom0
- Two foreign keys on the same column?
- ActiveRecord::Base.transaction - SystemStackError - stack level too deep: