开发者

mongoid query problem

I am trying to achieve the equivalent of this in mongoid (mongoid.org ORM):

 select * from parents 
 inner join children
 on parents.id = children.parent_id
 where children.created_at <= some_timestamp

Parent embeds a child, A child belongs to a parent

I have no issues up to this point: Parent.where(:child.exists => true), but I have no idea how I am supposed to do the equivalent of 'child.created_at'.lt => some_timestamp (Illegal to use a method on st开发者_如何学编程rings.)

Thanks


Mongoid uses UTC Timestamps internally, to work with a date in a query you can do the following:

:'child.created_at'.lt => Time.now.midnight.utc
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜