Feurio
2008-Mar-12 19:54 UTC
has_one association with :conditions: is this somehow possible?
What is the right way to achieve something like this: class Design < ActiveRecord::Base belongs_to :card_collection after_save :generate_images has_one :background, :as => :resourceable, :class_name => "Resource", :conditions => [ ''title = ?'', self.id ], :dependent => :destroy end -------------------- Everything here is working as expected. ONLY the conditions part is not working... The problem is that self.id is NOT the @my_design.id (the id of the active record design instance), but the object_id of the instance. HOW can I tell ActiveRecord that I want the @my_design.id ??? Thanks for any help! Feurio --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Mar-12 20:08 UTC
Re: has_one association with :conditions: is this somehow possible?
On 12 Mar 2008, at 19:54, Feurio wrote:> > What is the right way to achieve something like this: > > class Design < ActiveRecord::Base > belongs_to :card_collection > after_save :generate_images > > has_one :background, > :as => :resourceable, > :class_name => "Resource", > :conditions => [ ''title = ?'', self.id ], > :dependent => :destroy > end > > -------------------- > Everything here is working as expected. ONLY the conditions part is > not working... > > The problem is that self.id is NOT the @my_design.id (the id of the > active record design instance), but the object_id of the instance. HOW > can I tell ActiveRecord that I want the @my_design.id ??? >Set conditions to ''title =#{self.id}'' (make sure it''s single quotes not double quotes). Activerecord should interpolate it for you. Fred> Thanks for any help! > > Feurio > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Feurio
2008-Mar-16 16:50 UTC
Re: has_one association with :conditions: is this somehow possible?
Hi Fred, thanks for the hint. I finally found out how to get it work: --------- class Design < ActiveRecord::Base belongs_to :card_collection after_save :generate_images has_one :background, :as => :resourceable, :class_name => "Resource", :conditions => [ ''title = ?'', ''#{self.id}'' ], :dependent => :destroy end --------- ...by putting it in single quotes it worked. Thanks. Feurio On 12 Mrz., 21:08, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12 Mar 2008, at 19:54,Feuriowrote: > > > > > > > What is the right way to achieve something like this: > > > class Design < ActiveRecord::Base > > belongs_to :card_collection > > after_save :generate_images > > > has_one :background, > > :as => :resourceable, > > :class_name => "Resource", > > :conditions => [ ''title = ?'', self.id ], > > :dependent => :destroy > > end > > > -------------------- > > Everything here is working as expected. ONLY the conditions part is > > not working... > > > The problem is that self.id is NOT the @my_design.id (the id of the > > active record design instance), but the object_id of the instance. HOW > > can I tell ActiveRecord that I want the @my_design.id ??? > > Set conditions to ''title =#{self.id}'' (make sure it''s single quotes > not double quotes). Activerecord should interpolate it for you. > > Fred > > > Thanks for any help! > > >Feurio--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---