代码之家  ›  专栏  ›  技术社区  ›  philnash

铁路协会,habtm?多态性?二者都

  •  5
  • philnash  · 技术社区  · 17 年前

    1 回复  |  直到 17 年前
        1
  •  9
  •   Michiel de Mare    17 年前

    我将habtm梳理成一个单独的模型类ImageLink。然后你会得到:

    Project
      has_many :image_links, :as => :resource
    BlogPost
      has_many :image_links, :as => :resource
    ImageLink
      belongs_to :image
      belongs_to :resource, :polymorphic => true
    Image:
      has_many :image_links