多态模型,但想要它的多个版本

时间:2012-05-27 22:55:12

标签: ruby-on-rails-3 activerecord

我有一个多态资产模型,但想要资产类的两个不同版本。类似的东西:

class Location < ActiveRecord::Base
  has_many :assets, :as => :assetable, :order => 'position'
  has_many :assets :known_as => :cover_images, :as => :assetable, :order => 'position'

我看到了这个问题:Rails Polymorphic Association with multiple associations on the same model但是当我使用我的模型在Rails 3.1中实现时,它看起来像:

has_many :assets, :as => :assetable, :order => 'position'
has_one :header_photo, :class_name => 'Asset', :as => 'assetable', :conditions => {:assetable_type => 'header_asset'}, :dependent => :destroy

在控制台中查看:

SELECT `assets`.* FROM `assets` WHERE `assets`.`assetable_id` = 37 AND `assets`.`assetable_type` = 'Location' AND `assets`.`assetable_type` = 'header_asset' LIMIT 1

这不是我想要的。

我该怎么做?是否有处理此问题的语法?

THX

0 个答案:

没有答案