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.
on 2008-11-19 21:02
on 2008-11-19 21:53
On Nov 19, 8:02 pm, Misiek Sz <rails-mailing-l...@andreas-s.net> 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
on 2008-11-19 22:13
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.
on 2008-11-19 22:19
On 19 Nov 2008, at 21:13, Misiek Sz wrote: > 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