views:

615

answers:

1

I have just started investigating using more advanced models in Rails. One that I use regularly, with great success, is model where a many-to-many cross-reference relationship is accessed by a class that itself is a sub-class of the base class in the many-to-many relationship.

This way the cross-reference class can act as a stand-in for the base class.

A good example is where a navigation hierarchy node (NavigationNode) is cross-referenced to a user role. At the cross-reference point a class (RoleNavigationNode) can inherit from NavigationNode and still have intimate knowledge of the user role.

My question is (in the case above) can RoleNavigationNode inherit from NavigationNode and yet access the cross-reference table rather than the one that NavigationNode accesses -- this of course using ActiveRecord.

I have not investigated polymorphic association, which may be more appropriate.

Thanks in advance...,

+1  A: 

tried set_table_name on the subclass?

Also, look into setting @abstract_class in model classes.

Lastly, what you need may simply be a Mixin that you include in both models.

Anyway, what you're trying to do sounds rather un-ActiveRecord-ish. You might want to post a clearer example of what you're trying to achieve, maybe we'll be able to come up with something simpler.

kch
It may be a bit ridiculous responding to your post like this (four months later). But thanks... I had forgotten where I posted this question. I was milling around the web lately because this issue has come up again. Anyway I will look into your comments - and it is a little un-something-like I realize.