Dear all, I have a problem with the relations of a model. The problem is the following. I have 2 models. Page and PeContainer. Page: has_and_belongs_to_many :pe_containers PeContainer belongs_to :page has_many :pages>Page---->PeContainer -------->Page ------------>PeContainer So my mainproblem is to get the parentpage of the PeContainer. I can only access the childpages. Can anyone help? Thanks in advance! Kind regards Alex --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 4/10/07, physalias <alexander.funke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Page: > has_and_belongs_to_many :pe_containers > > PeContainer > belongs_to :page > has_many :pages > > >Page > ---->PeContainer > -------->Page > ------------>PeContainerHmm, that''s a very interesting relationship. [1] Something to try first -- and even if this is not part of the problem, It may help you in debugging -- is to name the relationships more directly. In PeContainer, name them "parentpage" and "childpages", etc. [2] I think your problem might lie in the fact that in your Page model you have only declared one relationship, when really there are two. Consider the case of a Book, which has an author and an editor, both of which are People. You would declare the relationships seperately, you would not say "has many People". Similarly, in this case you should HABTM :parent_containers and HABTM :child_containers. Let us know if that gets you anywhere. -- John Joseph Bachir http://lyceum.ibiblio.org http://blog.johnjosephbachir.org aim/yim/msn/jabber.org/gtalk: johnjosephbachir 713-494-2704 http://jjb.cc --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of physalias > Sent: Tuesday, April 10, 2007 12:36 PM > To: Ruby on Rails: Talk > Subject: [Rails] Has_many and belons_to Problem > > > Dear all, > > I have a problem with the relations of a model. The problem > is the following. > > I have 2 models. Page and PeContainer. > Page: > has_and_belongs_to_many :pe_containers > > PeContainer > belongs_to :page > has_many :pages > > >Page > ---->PeContainer > -------->Page > ------------>PeContainer > > So my mainproblem is to get the parentpage of the > PeContainer. I can only access the childpages. Can anyone > help? Thanks in advance!Looks to me like your page model is incorrect, judging from your text diagram. Assuming your model is a tree with alternating node types, you probably want: Page: belongs_to :pe_container (parent) has_many :pe_containers (children) PeContainer: belongs_to :page (parent) has_many :pages (children) - donald --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 4/10/07, physalias <alexander.funke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > So my mainproblem is to get the parentpage of the PeContainer. I can > only access the childpages. Can anyone help? Thanks in advance! >I just re-read your email and realized that I did not address the problem you stated :). But I think making your relationships more explicit is a good place to start. -- John Joseph Bachir http://lyceum.ibiblio.org http://blog.johnjosephbachir.org aim/yim/msn/jabber.org/gtalk: johnjosephbachir 713-494-2704 http://jjb.cc --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 4/10/07, Ball, Donald A Jr (Library) <donald.ball-GjtI+QwuxAR68HQyEA6aog@public.gmane.org> wrote:> > Looks to me like your page model is incorrect, judging from your text > diagram. Assuming your model is a tree with alternating node types, you > probably want: > > Page: > belongs_to :pe_container (parent) > has_many :pe_containers (children) > > PeContainer: > belongs_to :page (parent) > has_many :pages (children) >Yes, Donald''s suggestion is better than mine :) (although I would still name them more specifically) -- John Joseph Bachir http://lyceum.ibiblio.org http://blog.johnjosephbachir.org aim/yim/msn/jabber.org/gtalk: johnjosephbachir 713-494-2704 http://jjb.cc --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dear all! Thanks for fast answering. I changed the Modelrelations to the settings Donald wrote. But this didn''t help. I can''t rename my models, because I have an unlimited tree. So here is an example of what i do: I have a page (id=1) This page has a container (id=1) This Container has 2 pages (id=2 & id=3) Page 1 has a container (id=2) Page 2 has a container (id=3) So now I have to walk up the tree. So if I have the container (id=1) I need to get the parentpage (id=1), but I only can access the 2 childpages. So is this issue resolvable? Thanks in advance! Kind regards Alex On 10 Apr., 20:10, "John Joseph Bachir" <johnjosephbac...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 4/10/07, Ball, Donald A Jr (Library) <donald.b...-GjtI+QwuxAR68HQyEA6aog@public.gmane.org> wrote: > > > > > Looks to me like your page model is incorrect, judging from your text > > diagram. Assuming your model is a tree with alternating node types, you > > probably want: > > > Page: > > belongs_to :pe_container (parent) > > has_many :pe_containers (children) > > > PeContainer: > > belongs_to :page (parent) > > has_many :pages (children) > > Yes, Donald''s suggestion is better than mine :) > > (although I would still name them more specifically) > > -- > John Joseph Bachirhttp://lyceum.ibiblio.orghttp://blog.johnjosephbachir.org > aim/yim/msn/jabber.org/gtalk: johnjosephbachir > 713-494-2704http://jjb.cc--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---