Reputation: 7210
I have an orde field on one of my models, that model also has a is_milestone? method which returns true or false depending on whether the order is either a 50th or 100th milestone.
I wish to select all the items that are milestones but can this be done by using the is_milestone? method?
I currently have:
@milestones = Model.where(:is_milestone?).order('order ASC')
But it doesn't work and I think I have the syntax wrong but unsure how it should be written.
Any thoughts?
Upvotes: 0
Views: 112
Reputation: 10898
No - You cannot ask the database to do a query which requires interaction with your Ruby code.
The only way you'd be able to get this to work is to create an is_milestone
attribute on your model and store the boolean value within the database. You could perhaps populate this value with an after_save
callback which counted the milestones and set the value to true if it was either the 50th or 100th one.
Upvotes: 1