作者:手机用户2602922857 | 来源:互联网 | 2023-01-26 16:10
IhavejuststartedinvestigatingusingmoreadvancedmodelsinRails.OnethatIuseregularly,wit
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.
我刚刚开始研究在Rails中使用更高级的模型。我经常使用的一个模型非常成功,就是多对多引用关系被一个类访问,这个类本身就是多对多关系中的基类的子类。
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.
一个很好的例子是导航层次节点(NavigationNode)与用户角色交叉引用。在交叉引用点上,类(RoleNavigationNode)可以从NavigationNode继承,并且仍然对用户角色有深入的了解。
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.
我的问题是(在上面的例子中)RoleNavigationNode可以从NavigationNode继承,但仍然可以访问交叉引用表,而不是NavigationNode访问的表——当然,这使用了ActiveRecord。
I have not investigated polymorphic association, which may be more appropriate.
我还没有研究多态关联,这可能更合适。
Thanks in advance...,
提前谢谢…
2 个解决方案