Pavel
Pavel

Reputation: 131

rails 3.0.1 active_record

How is it possible with active_record?

u = User.all
u = u.where(:id => 1)

NoMethodError: undefined method `where' for # u.class => Array

Can't chain conditions :(

Upvotes: 1

Views: 147

Answers (1)

Damien MATHIEU
Damien MATHIEU

Reputation: 32629

The all method executes the query. So you can't chain after using it.

u = User.where(:id => 1)
u.where(:id => 2)

This would execute the query WHERE id = 1 AND id = 2

Upvotes: 3

Related Questions