I have the following data model in a Rails 2.3 application
class PortraitSubject has_many :portraits has_one :primary_portrait, :through => :portraits, :source => :asset, :conditions => ['portraits.primary = ?', true] has_many :supplementary_portraits, :through => :portraits, :source => :asset, :conditions => ['portraits.primary = ?', false] ... end class Portrait belongs_to :portrait_subject belongs_to :asset ... end
I want to create related proxy models using Rails, but an attempt to create primary_portrait will fail. I.e.
# This works subject = PortraitSubject.new subject.supplementary_portraits.build subject.save # This doesn't subject = PortraitSubject.new subject.build_primary_portrait # => NoMethodError: undefined method `build_primary_portrait' for #<PortraitSubject:0x007ff16fe38948>
I'm not sure what I'm doing wrong. Looking through the Rails guides, it looks like this is possible with the has_one relation. Any help would be greatly appreciated.
source share