我尝试使用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}}。
知道怎么做到这一点吗?
答案 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)