Hi to everyone,

I have the following models:

class Attachment < ActiveRecord::Base
  has_attachment  :content_type => [:image, 'application/pdf'],
                  :max_size => 3.megabytes,
                  :path_prefix => '../private/attachments',
                  :storage => :file_system,
                  :processor => :rmagick,
                  :thumbnails => { :small => '32x32', :medium =>
'64x64', :large => '256x256' }

  validates_as_attachment

  belongs_to  :attachable, :polymorphic => true
end

class Maker < ActiveRecord::Base
  validates_presence_of :name, :on => :create, :message => "can't be
blank"
  validates_uniqueness_of :name, :message => 'name must be unique'
  validates_presence_of :description, :on => :create, :message => "can't
be blank"

  has_one :attachment, :as => :attachable, :dependent => :destroy
  has_one :logo, :through => :attachment, :source => :attachable,
:source_type => 'Maker', :dependent => :destroy,
                      :conditions => ['attachments.content_type = ?',
'image/jpeg' ]

  has_many :products

  def deletable?
    self.products.empty?
  end

end

What I would like to accomplish is to have a "logo" association on the
"Maker" model which allows
me to fetch the logo (eventually) associated to the maker.

The row:

  has_one :logo, :through => :attachment, :source => :attachable,
:source_type => 'Maker', :dependent => :destroy,
                      :conditions => ['attachments.content_type = ?',
'image/jpeg' ]


produces the same results of:

has_one :another_logo, :class_name => 'Attachment', :foreign_key =>
'attachable_id', :conditions => ['attachable_type = ?', 'Maker' ]

Which one is the best approach to achieve the desired result?

Thanks in advance for your help
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to