Ruby on Rails Monday, January 31, 2011

On Jan 31, 9:09 am, frankblizzard <tmaxim...@googlemail.com> wrote:

> @assignments = Assignment.where("user_id = ?", current_user.id)
>
> but if I try the same thing with projects I get an error.... as there
> is no user_id column in projects..
>
> there must be an elegant way to query this with Active Record, right?
>
You wouldn't normally use where (or find in previous versions of
rails) for this sort of stuff. Setting up associations with has_many
etc. means you can do current_user.assignments, current_user.projects
etc.

Fred

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