0

I have a polymorphic asset model but would like two different versions of it for an asset class. Something like:

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

I saw this question: Rails Polymorphic Association with multiple associations on the same model but when I implemented in Rails 3.1 with my models, it looked like:

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

Looking in console, I see:

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

which is not what I want.

How would I do this? Is there syntax for handling this?

thx

Community
  • 1
  • 1
timpone
  • 19,235
  • 36
  • 121
  • 211
  • sorry but could not understand your question properly as far as I understand you need to use assets model as polymorphic so please elaborate it properly. You can also find good example on polymorphic association on http://railscasts.com/episodes/154-polymorphic-association – urjit on rails May 28 '12 at 05:36
  • i'm familiar with polymorphic associations hence - this is a variation on handling different ones which might be inconsistent with rails 3 which is what the previous answer addresses. – timpone May 28 '12 at 16:48

0 Answers0