Hi All,
I can work around this if it isn't possible, but I am looking to create a scope for a model which returns records based on the result of a model function.
Essentially, I have the following:
class contract has_many contract_statuses
def current_status(date) .... end end
class contract_status belongs_to :contract belongs_to :status end
class status has_many :contract_statuses end
The contract_statuses are there to track the status of a contract over time with the latest being the current status for a particular contract. A 'status' simply has a 'name' field.
In my contract model, i have a current_status function which returns the contract_status record that was relevant as a particular time, given a date parameter.
The scope I would like would be something like contracts.active, where active relates to the name of the current status. Ideally, I would like to get the status through the current_status method of the contract, but I've not been able to find a way to do this in a scope.....
Is this possible?