On 7 April 2010 13:21, jeb <jo...@ibiz.se> wrote:
> There is no managers table, just a relation. Thats the thing:
>
>  belongs_to :manager, :class_name => "User", :foreign_key =>
> "manager_id"

So has it included the users table then?  Post the whole sql.

Colin

>
>
> :-) j
>
> On 3 Apr, 15:01, Colin Law <clan...@googlemail.com> wrote:
>> On 3 April 2010 11:42, jeb <jo...@ibiz.se> wrote:
>>
>>
>>
>>
>>
>> > Hi,
>>
>> > The error message is:
>> > SQLite3::SQLException: no such column: manager.name: SELECT
>> > "stores"."id" AS t0_r0, "stores"."customer_id" AS t0_r1, AND ON AND ON
>>
>> > There sure is a name column in the users model.
>>
>> > This works fine but does not give the same result of course:
>> > named_scope :manager_name, lambda{|name| {:include
>> > => :users, :conditions => ['users.name = ?', name ]}}
>>
>> > :-) j
>>
>> > On 2 Apr, 10:56, Colin Law <clan...@googlemail.com> wrote:
>> >> On 2 April 2010 09:06, jeb <jo...@ibiz.se> wrote:
>>
>> >> > Hi all,
>>
>> >> > I can't get this named scope to work. Each store has a number of
>> >> > users. Each store can have one manager. I ant to use a nemed scope to
>> >> > find the manager by name. Have I got this totally backwards?
>>
>> >> > Help appreciated
>> >> > :-) jonas
>>
>> >> > 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 ]}}
>>
>>  Has it included the managers table?  You have not shown enough of the
>> sql to see.  Try it with :include => :managers  (plural)
>>
>> Colin
>>
>>
>>
>>
>>
>> >> That looks ok to me, assuming that thestorestable has a manager_id
>> >> column.  Remember that the named scope will return an array ofstores
>> >> containing all thestoreswith a manager of that name.
>>
>> >> If you have already a store in @store  then to get the managers name
>> >> you just need @store.manager.name of course.
>>
>> >> If that doesn't help post the error you are getting and the code
>> >> around the error.
>>
>> >> Colin
>>
>> > --
>> > 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-t...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > rubyonrails-talk+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/rubyonrails-talk?hl=en.
>
> --
> 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-t...@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

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

Reply via email to