ActiveRecord:在created_at之后检索updated_at为24小时或更长时间的所有记录

时间:2016-08-04 06:20:03

标签: ruby-on-rails activerecord

我尝试使用ActiveRecord和Postgres数据库查找在创建(+(SEL)getterForPropertyWithName:(NSString*)name { const char* propertyName = [name cStringUsingEncoding:NSASCIIStringEncoding]; objc_property_t prop = class_getProperty(self, propertyName); const char *selectorName = property_copyAttributeValue(prop, "G"); if (selectorName == NULL) { selectorName = [name cStringUsingEncoding:NSASCIIStringEncoding]; } NSString* selectorString = [NSString stringWithCString:selectorName encoding:NSASCIIStringEncoding]; return NSSelectorFromString(selectorString); } +(SEL)setterForPropertyWithName:(NSString*)name { const char* propertyName = [name cStringUsingEncoding:NSASCIIStringEncoding]; objc_property_t prop = class_getProperty(self, propertyName); char *selectorName = property_copyAttributeValue(prop, "S"); NSString* selectorString; if (selectorName == NULL) { char firstChar = (char)toupper(propertyName[0]); NSString* capitalLetter = [NSString stringWithFormat:@"%c", firstChar]; NSString* reminder = [NSString stringWithCString: propertyName+1 encoding: NSASCIIStringEncoding]; selectorString = [@[@"set", capitalLetter, reminder, @":"] componentsJoinedByString:@""]; } else { selectorString = [NSString stringWithCString:selectorName encoding:NSASCIIStringEncoding]; } return NSSelectorFromString(selectorString); } )后至少24小时或更长时间内更新的所有记录(<{1}}。

知道怎么做到这一点吗?

3 个答案:

答案 0 :(得分:3)

您可以通过直接使用hours

来检查条件,从而提供更明确的条件

Model.where("updated_at >= created_at + interval '24' hour")

返回查询

SELECT {模型{1}} {模型{1}}

检查此查询及其对我的模型的正常工作,希望也适合你,

答案 1 :(得分:0)

您可以为此

编写范围
scope :scope_name , -> () { where("updated_at::date > created_at::date") } 

答案 2 :(得分:0)

您可以尝试使用以下查询

Model.where("updated_at > (Date(created_at) + integer '1')")

这是reference