This question is more about how things work in an MVC architecture based ORM application. I want to know which controller to write code into when there is a many to many relationship between 2 models. Example, I have a model A and model B with respective controllers and have a many to many realastionship. I want to list Bs that are associated with A in using bridge table. Which controller should the code for this go since both are equally related. Chirantan --~--~---------~--~----~------------~-------~--~----~ 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 Oct 10, 5:34 am, Chirantan <chirantan.rajh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This question is more about how things work in an MVC architecture > based ORM application. I want to know which controller to write code > into when there is a many to many relationship between 2 models. > > Example, > > I have a model A and model B with respective controllers and have a > many to many realastionship. I want to list Bs that are associated > with A in using bridge table. Which controller should the code for > this go since both are equally related. > > ChirantanHi Chirantan. Controller methods generally map to actions that are performed on models. So a method named "new" in the User model would allow you to create a new User. In other words, if you want to do something to ModelA, you''d put the method in ModelA''s controller. To answer your question, if I wanted to list all Bs associated with a particular A, I would probably create a method in the A controller called "list_Bs". Hope that helps, Nick --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Nick. It helped. I went with the same approach. Thank you for your clarification. Chirantan On Oct 10, 6:30 pm, Nick <n...-qGbiljoI0DQkmLvzuZlaBw@public.gmane.org> wrote:> On Oct 10, 5:34 am, Chirantan <chirantan.rajh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > This question is more about how things work in an MVC architecture > > based ORM application. I want to know which controller to write code > > into when there is a many to many relationship between 2 models. > > > Example, > > > I have a model A and model B with respective controllers and have a > > many to many realastionship. I want to list Bs that are associated > > with A in using bridge table. Which controller should the code for > > this go since both are equally related. > > > Chirantan > > Hi Chirantan. Controller methods generally map to actions that are > performed on models. So a method named "new" in the User model would > allow you to create a new User. In other words, if you want to do > something to ModelA, you''d put the method in ModelA''s controller. > > To answer your question, if I wanted to list all Bs associated with a > particular A, I would probably create a method in the A controller > called "list_Bs". > > Hope that helps, > Nick--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---