0

我有一个多态资产模型,但想要一个资产类别的两个不同版本。就像是:

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

这不是我想要的。

我该怎么做?有处理这个的语法吗?

谢谢

4

0 回答 0