iGEL
iGEL

Reputation: 17412

Rails: Getting the Relation without where or limit

If I do Product.where(title: "asdf"), I get an Relation object. Some time later, I can do an each on that object, and at this point, the query gets executed. But sometimes, I want all the objects, so I won't need a where clause or something. I do Product.all then, but this will execute the query immediately. If it turns out, that I won't need the products in the view, the query was unnecessary. I could do Product.where("1=1"), but it doesn't feel right.

Is there some kind of Product.relation or something like that?

Upvotes: 0

Views: 62

Answers (1)

apneadiving
apneadiving

Reputation: 115541

I guess scoped should do the trick. See doc.

Upvotes: 2

Related Questions