Friday, July 29, 2011

[Rails] Re: scope determined by model function call

Don't suppose anyone has any thoughts regarding this?


Thanks


Paul

On Jul 27, 12:19 pm, paulo <paul.a.taylo...@gmail.com> wrote:
> 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?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate