activerecord - Use a find hash in Rails 3.x? -
is there non-deprectated option in rails 3 can pass data structure in execute query, rather use method chaining approach ?
consider hash representing set of critieria limiting set of records (say, documents)..
{ :conditions => { :account_id => 2 }, :limit => 5, # page size :offset => 5, # (page-1) * page_size :sort => 'id desc' } this may come url such as:
/documents.js?page_size=5&page=2&sidx=id&sord=desc&filter[account_id]=2 and want avoid issues of order-importance in translation of hash sequential series of calls of methods:
# 'right', or better ? document.offset(5).where(:account_id => 2).limit(5) document.where(:account_id => 2).limit(5).offset(5) i'm concerned programmatic transformation of set of query criteria inferred http parameters or json objects may more complicated if have walk hash , created chained method calls.
you can use classic find method:
document.all :conditions => { :account_id => 2 }, :limit => 5, :offset => 5, :order => "id desc"
Comments
Post a Comment