Open cfeckardt opened 9 years ago
Can you think of other constraints you might want support for?
Uniqueness constraints is definitely, the most critical, however the dream would be:
Perhaps a class method like +(BOOL)[RLMObject validateValue:forProperty:]
would be the simplest way to support arbitrary validation rules, although adding that method would likely have a significant performance impact, even when that method isn't overridden.
We could explicitly support specific types of constraints for improved performance, but that doesn't seem like a scalable approach.
For the time being, you can use an ignored property to validate properties before setting them:
@interface Person : RLMObject
@property NSString *name;
@property NSString *persistedName;
@end
@implementation Person
- (NSString *)name {
return self.persistedName;
}
- (void)setName:(NSString *)name {
if (/* custom validation rules */) {
self.persistedName = name;
} else {
// handle invalid value
}
}
+ (NSArray *)ignoredProperties {
return @[@"name"];
}
@end
@jpsim we could always use key-value validation if we wanted to provide arbitrary validation hooks?
+1 for uniqueness constraint
Not that other constraints won't be useful :)
+1 for uniqueness constraint. I'm presently rolling my own.
+1 for validation. I would really like to be able to do custom validation code.
It would be nice if there was a function similar to CoreData's validateForInsert()
on Object
that could be overridden for validation.
I would be willing to make a PR to include a validateForInsert()
function. Would that be something that you guys are interested in?
Implementing unique fields, which allow the identification of a record by a field that is not the primary key in massive insertions would be very useful.
Any news about this?, this is one of the biggest limitations of realm at this time, I have used it for 2 years and it is very necessary to create unique fields.
I think the understanding is that most enforced validation rules would have a significant performance impact. Likely even when the validation isn't being used.
When you need to validate data, you should do your own validation prior to writing your Realm Objects to the DB.
I have seen the suggestion of including a method that allows to choose a field as a unique key to insert records, if implemented something like that would cover a large part of the current problems. And I believe that it would not affect the structure or the performance of the rest of things
So is this still not implemented? No arbitrary columns (String) can be unique?
As a user, I would like to be able to put constraints on certain columns without making them primary keys.
For example, a uniqueness constraint on an e-mail field.