Tuesday, February 28, 2012

[Rails] Re: Scoped Activerecord query

@avenger_powers = Power.where(whatever).includes(User.all.superhero)

On Feb 28, 12:36 am, simpleton <brand.magn...@gmail.com> wrote:
> I have a User model with a scope :superhero and I want to do an AR
> query along the lines of:
>
> @avengers_powers = Power.where(etc.).includes(User.where( #{this is
> where I want to limit by superhero scope} ))
>
> My users schema is:
>
> create_table "users", :force => true do |t|
>     t.string   "uid"
>     t.string   "name"
>     t.datetime "created_at"
>     t.datetime "updated_at"
>     t.string   "token"
>     t.text     "ability"
>     t.string   "location"
> end
>
> My user model has:
>
> scope :superhero, where("ability like '%laser vision%' OR ability like
> '%invisibility%'")
> scope :hobo, where("location like '%cardboard box%'")
>
> Seeing as :superhero and :hobo aren't attributes on the user model,
> how would I query it?

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate