rubyonrailsin

A Ruby and Rails talk

Friday, April 2, 2010


Re: [Rails] named_scope when using foreign keys

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

On 2 April 2010 09:06, jeb <jonas@ibiz.se> wrote:
> class Store < ActiveRecord::Base
>  has_many :users, :dependent => :destroy
>  belongs_to :manager, :class_name => "User", :foreign_key =>
> "manager_id"
>  named_scope :manager_name, lambda{|name| {:include
> => :manager, :conditions => ['manager.name = ?', name ]}}


You don't say what errors you're getting, but I'd suggest that if your
tables follow the naming conventions, the conditions should be:
:conditions => ['managers.name = ?', name ]

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive