Rails: Many to many polymorphic relationships

前端 未结 7 2071
孤城傲影
孤城傲影 2021-01-30 00:17

See comments for updates.

I\'ve been struggling to get a clear and straight-forward answer on this one, I\'m hoping this time I\'ll get it! :D I definitely have

7条回答
  •  无人及你
    2021-01-30 00:56

    Have you pursued that brute force approach:

    class Task 
      has_many :stores
      has_many :softwares
      has_many :offices
      has_many :vehicles
    
      def targets
        stores + softwares + offices + vehicles
      end
      ...
    

    It may not be that elegant, but to be honest it's not that verbose, and there is nothing inherently inefficient about the code.

提交回复
热议问题