ruby on rails 3 - RoR Search conditions comparing two columns -


what want following:

a = assignment.all(:conditions => { :end_date < :start_date }) 

i want select records on end_date before start_date.

i don't want ending writing a
for each, push array if end_date earlier start_date.

how can achieve in pretty 'railsy'-way?

thank in advance.

edit:

i think problem comparing values of both columns. (allmost) every query comparing cell-value input-value.
shot in dark, maybe 1 in right direction ?

haven't figured out solution.

it's been while here nevertheless, can use areltable method:

t = assignment.arel_table assignment.where(t[:end_date].lt(t[:start_date])) 

the condition predicates documentation: http://www.rubydoc.info/github/rails/arel/arel/predications

the areltable documentation: http://www.rubydoc.info/github/rails/arel/arel/table

and guide: http://jpospisil.com/2014/06/16/the-definitive-guide-to-arel-the-sql-manager-for-ruby.html


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -