Reputation: 171351
Is there a shorter way to write this ?
Job.all(:conditions => "job_source_id=1")
Upvotes: 2
Views: 2169
Reputation: 18784
I usually like to use scopes for this kind of thing like so:
# in the model
scope :from_sales, :conditions => { :job_source_id => 1 }
Then, from anywhere, I can just call:
Job.from_sales.all
This lets me express myself in my problem domain instead of sql.
Upvotes: 0
Reputation: 3069
Use the Dynamic Finders
http://guides.rubyonrails.org/active_record_querying.html#dynamic-finders
Job.find_by_source_id(1)
Upvotes: 1
Reputation: 96944
A little shorter and more readable:
Job.where :job_source_id => 1
Upvotes: 5