Forum: Ruby on Rails setting default on "has_one" failure

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dorian M. (Guest)
on 2006-01-26 06:07
(Received via mailing list)
Hi there,
I have a model for a Film, which:

  has_and_belongs_to_many :artists
  has_many                :stills
  has_one                 :preview_image,
                          :class_name => "Still",
                          :conditions => "priority='main'"

the has_one:preview_image and has_many:stills obviously draw from the
same table.

I was wondering if there is a way to set a default value for
:preview_image (say :stills[0] for example) if has_one fails to retrieve
a :preview_image from the db?

If it's easier to send me link, then I'd happily read a page about what
you can do to models, as I'm finding it difficult to do very much in the
model pages.



I do things for love or money
+44 (0)7941 219 501
aim:oulalipo | yahoo:tachekent
This topic is locked and can not be replied to.