btw, I went with this for the case in question - probably a cheaper
operaiton anyway:
  def self.contract(month)
    d = Date.from_contract_month(month)
    month_start = Date.new(d.year, d.month, 1)
    month_end = DateRule.apply(month_start, "+1m-1d")
    all(:expiration_date => (month_start..month_end))
  end

still interested in the db-function abstraction in general though.

On Jan 11, 8:13 pm, Patrik Sundberg <patrik.sundb...@gmail.com> wrote:
> Hi,
>
> I'm trying to convert this named scop from AR to DM:
>   named_scope :contract, lambda { |month|
>     d = Date.from_contract_month(month)
>     { :conditions => ['EXTRACT(YEAR from expiration_date) = ? and
> EXTRACT(MONTH from expiration_date) = ?',
>                       d.year, d.month ]
>     }
>   }
>
> It uses some postgres functions and I was wondering if there's any
> abstractions for things like this in DM ?
>
> Sort of like
> def self.contract(month)
>   all(:expiration_date.year => d.year, :expiration_date.month =>
> d.month)
> end
>
> I can do it with an SQL query in DM, just wanted to check if there's
> some abstraction that can get me out of doing that. I saw a thread
> related to this sort of thing from end of 2008 and dug around on
> github but didn't see anything.
>
> Thanks,
> Patrik
-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to datamap...@googlegroups.com.
To unsubscribe from this group, send email to 
datamapper+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.


Reply via email to