Hi, I was wondering if there''s a way to know the associations needed to reach a model from another, i.e. I have a Customer, I know it has some Invoices, each of these has more InvoiceRows which belongs to an InvoiceRowDescription, I would like to know if there''s a way to automagically build something like this (for an auto generated named scope''s join key): {:invoices => {:invoice_rows => :invoice_row_description}} knowing just that the current model is Customer, and the last model is InvoiceRowDescription Thanks, G. --~--~---------~--~----~------------~-------~--~----~ 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 Mar 21, 6:23 pm, Gabriele Tassoni <gabriele.tass...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > I was wondering if there''s a way to know the associations needed to > reach a model from another, i.e. > I have a Customer, I know it has some Invoices, each of these has more > InvoiceRows which belongs to an InvoiceRowDescription, I would like to > know if there''s a way to automagically build something like this (for > an auto generated named scope''s join key): >There''s not something builtin (although it does sound like it would be a relatively simple graph traversal exercise to produce something like this (picking the ''best'' path if there were multiple ones might be trickier)). Fred> {:invoices => {:invoice_rows => :invoice_row_description}} > > knowing just that the current model is Customer, and the last model is > InvoiceRowDescription > > Thanks, > > G.--~--~---------~--~----~------------~-------~--~----~ 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 21 Mar, 19:58, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 21, 6:23 pm, Gabriele Tassoni <gabriele.tass...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > There''s not something builtin (although it does sound like it would be > a relatively simple graph traversal exercise to produce something like > this (picking the ''best'' path if there were multiple ones might be > trickier)).Indeed there are multiple choices... it looks like an operations research problem... I could look at all the model_ids'' fields in the last model and traverse them up to the first of the chain (the one which don''t belongs to some other model), if I find the current model in this chain, I can stop, otherwise I take other associations chains... in case of loops.. I can consider it a dead end... but this optimal approach can explode in terms of computational complexity (ok, we are dealing with very fiew elements, possibly dozens, rarely an app can have more than 100 models... thus it won''t be a real problem, but.... who knows!) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---