Is there a method to find out whether given column is an association or not? For example, I would like iterate through all columns in a given record and do something for each column that is an association. -- 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 -~----------~----~----~----~------~----~------~--~---
On Nov 19, 8:02 pm, Misiek Sz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Is there a method to find out whether given column is an association or > not? > For example, I would like iterate through all columns in a given record > and do something for each column that is an association.You might want to approach thing from the other end: SomeClass.reflections gives you an object for each assocation (and aggregation) a class has. Fred> -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thats a good suggestion, but I don''t think it will work for me. What I''m trying to do is give users capability to clone a specific record and clone all associations with it as well. The thing is that I have many models and a lot different associations and I don''t want hard code them all. I would like to have something dynamic that identifies all the assoc for a specific record and then clones those and ties them to the new parent record created. Sort of like a deep cloning, but without specifying the associations. -- 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 -~----------~----~----~----~------~----~------~--~---
On 19 Nov 2008, at 21:13, Misiek Sz wrote:> > Thats a good suggestion, but I don''t think it will work for me. What > I''m > trying to do is give users capability to clone a specific record and > clone all associations with it as well. The thing is that I have many > models and a lot different associations and I don''t want hard code > them > all. I would like to have something dynamic that identifies all the > assoc for a specific record and then clones those and ties them to the > new parent record created. Sort of like a deep cloning, but without > specifying the associations. >my main point was that that is where you will have to derive the information from. There''s nothing that says that column x is an association (although if it''s an integer ending in _id it''s very likely). But by looking at the reflections, you can list all associations, and thus all the columns involved (and you''ll have to do this if you wanted the has_manys). Just looking at columns probably might also give you trouble with things like polymorphic associations. Fred> -- > 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 -~----------~----~----~----~------~----~------~--~---