Well, as in the title, I''m pretty new to rails, though I''ve been messing around with it on and off for a few months. nothing big, just some test projects with everything pretty simple. Well, right now I''m trying to put something together and I''m having trouble conceptualizing just how to model things. I''m putting together what basically amounts to a family tree - I have people, and I have relationships between people (ie, a father may have a daughter or two and a wife). I''ve tried person has_many :relationships and relationship belongs_to :person, but that seemed to just confuse me and my app. Likewise, I had trouble putting together a coherent db schema, as a relationships table would need two different person_id''s (continuing the example, one for the father, and one for his daughter). With this app, I would need to be able to, when pulling a page up about a certain person, have links with names to those people that the person has relationships with. Any suggestions? I''m new to rails, so any advice is welcome. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Check out acts_as_tree. It may be able to help you b/c it enables you to model hierarchies. In person.rb you would have: class Person < ActiveRecord::Base acts_as_tree :order=>"age" <-- or however you want to sort it end Make sure that in your schema you have a field called parent_id. Somethin like: create table people ( id int not null auto_increment, parent_id int , name varchar(200) not null, created_on datetime not null, updated_on datetime not null, constraint fk_person_parent foreign key (parent_id) references people(id), primary key (id) ); When searching you can use an idiom I don''t quite remember to pull up all the children as well. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
That''s perfect according to the description I gave, thanks a lot! Looked up the proper stuff for calling up the children from the page, and it works just as advertised. (found info on it here: http://api.rubyonrails.org/classes/ActiveRecord/Acts/Tree/ClassMethods.html) However, if I were to expand this to a Father + Mother both being able to branch down to the same children (as families tend to work ;), how would I do this? Is there something similar to acts_as_tree that allows for multiple parents? Thanks again :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---