Welcome, Guest
Username Password: Remember me

Validate uniqueness of entity based on sub relathionship property
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Validate uniqueness of entity based on sub relathionship property

Validate uniqueness of entity based on sub relathionship property 1 year, 2 months ago #1

Hi!

I was wondering how to validate the uniqueness of an entity based on sub relathionship property? For instance a house has an adresse. The adresse has a street. The house title property is "Adresse.Street". I want to make sure there is no house with the same adresse created.

House->Adresse.Street

Thanks!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 7

Re: Validate uniqueness of entity based on sub relathionship property 1 year, 2 months ago #2

Hi Harold,

The easiest way to do this is via the SCTableViewCellDelegate method called "valueIsValidForCell". Here is some sample code:

 
- (void)viewDidLoad
{
...
SCClassDefinition *adresseClassDef = [SCClassDefinition definitionWithEntity:...];
adresseClassDef.uiElementDelegate = self; // enable SCTableViewCellDelegate methods
SCPropertyDefinition *streetPropertyDef = [adresseClassDef propertyDefinitionWithName:@"street"];
streetPropertyDef.autoValidate = FALSE;
...
}
 
// Make sure your VC conforms to the SCTableViewCellDelegate protocol for
// this method to get called
- (BOOL)valueIsValidForCell:(SCTableViewCell *)cell
{
if([cell isKindOfClass:[SCTextFieldCell class]])
{
NSString *street = ((SCTextFieldCell *)cell).textField.text;
 
 
// now here you should load all your Core Data adresse entities in an array and
// compare their street attributes to "street". If street is found within
// the adresses, you should return FALSE, else return TRUE.
// Important Note: This can be much more optimized if you cache an array of
// streets beforehand instead of loading all the entities each time the street
// text is validated.
}
}
 


Hope this helps!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Validate uniqueness of entity based on sub relathionship property 1 year, 2 months ago #3

Hi thanks again for your swift reply!

The thing is that i need to now only about Houses with a specfied Adresse whith a specfic street. There could be other entities who have relationships with the Adresse entity (ex.: cars) which i don't need to know of.

Thanks!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 7

Re: Validate uniqueness of entity based on sub relathionship property 1 year, 2 months ago #4

I am completely lost now Harold
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Validate uniqueness of entity based on sub relathionship property 1 year, 2 months ago #5

Ok my bad.

I didn't understand what you meant in this comment:

// now here you should load all your Core Data adresse entities in an array and
// compare their street attributes to "street". If street is found within
// the adresses, you should return FALSE, else return TRUE.
// Important Note: This can be much more optimized if you cache an array of
// streets beforehand instead of loading all the entities each time the street
// text is validated.

So basically i have to go trough the adresses array and make sure they are related to a House entity. Then i can compare the streets. Hope i made myself a bit clearer now.

Thanks!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 7

Re: Validate uniqueness of entity based on sub relathionship property 1 year, 2 months ago #6

Exactly Good luck!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
Time to create page: 1.70 seconds