HABTM Polymorphic Relationship

前端 未结 2 1974
半阙折子戏
半阙折子戏 2020-12-01 09:13

I\'m pretty new to Rails, and i\'m trying to do a polymorphic HABTM relationship. The problem is that I have three models that I want to relate.

The first one is the

2条回答
  •  星月不相逢
    2020-12-01 10:03

    Resolveu parcialmente.

    It does solve the problem given the framework that we have at our disposal, but it adds "unnecessary" complexity and code. By creating an intermediary model (which I will call B), and given A -> B -> C being "A has_many B's which has_many C's", we have another AR Model which will load one more AR class implementation into memory once it is loaded, and will instantiate for the sole purpose of reaching C instances. You can always say, if you use the :through association, you don't load the B association, but then you'll be left with an even more obsolete model, which will only be there to see the caravan pass by.

    In fact, this might be a feature that is missing from Active Record. I would propose it as a feature to add, since it has been cause of concern for myself (that's how I landed in this post hoping to find a solution :) ).

    Cumprimentos

提交回复
热议问题