USING YOUR OWN PRIMARY KEY

As suggested above, simply ignore the fact that DBAccess has an inbuilt property called Id, it is required for maintaining relationships, events & support for the managed object layer.

If you add your own primary key column (bearing in mind that in SQLite there is no real difference between that or any other column, other than some small syntactic changes that the ORM will not make use of) you become responsible for calculating the allocated value for that column.

This is done using the –entityWillInsert method. ┬áThis is an atomic method and creates a lock, ensuring that two calls cannot collide at the same time.

 

- (BOOL)entityWillInsert {
    Person* p = [[[[Person query] orderDescending:@"personId"] limit:1] fetch].firstObject;
    self.personId = p ? p.personId+1 : 1;
    return YES;
}