Forum: Ruby on Rails Relationships in Rails...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fresh M. (Guest)
on 2009-01-26 11:18
I have 2 tables:

people (id, name)
children (id, parents_id, child_id)

parents_id = people.id and child_id = people_id also

So how I make a relationships in Rails?

And how can all search:

Children.find(:all, :conditions => ["parents.name LIKE 'Clin%' ???? Or
how???

And what if I want to add new child. Parents name is in people table,
but childs not, so how I do?
Martin H. (Guest)
on 2009-01-26 11:51
(Received via mailing list)
Sounds like a many to many relationship, in which case you need to
declare has_and_belongs_to_many on both people and children. The
relationship then works through a join table. If you did this, you'd
need to re think your model a little and your find and add problems
would be different.
Martin

On Jan 26, 9:18 am, James B. <removed_email_address@domain.invalid>
Juan José Vidal (Guest)
on 2009-01-26 13:50
(Received via mailing list)
I think that the best solution to your problem is to use acts_as_tree

http://github.com/rails/acts_as_tree/tree/master

Martin H.
escribió:> Sounds like a many to many relationship, in which case you need to
This topic is locked and can not be replied to.