Hello,
I have two tables related: DataEntered and Model
DataEntered -currentModel
Model
One DataEntered can have only ONE Model, but a Model can stay into many DataEntered.
The relationship is from DataEntered to Model (No To Many-relathionship) and no inverse relation.
XCode generates the setters for DataEnteredModel:
@property (nonatomic, retain) NSSet * current_model;
- (void)addCurrent_modelObject:(CarModel *)value;
- (void)addCurrent_model:(NSSet *)value;
I have a Table and when I select a model, I want to store it to DataEntered:
Model *model = [fetchedResultsController objectAtIndexPath:indexPath];
NSLog(@"Model %@",model.name); // ==> gives me the correct model name
[dataEntered addCurrent_modelObject:model]; // ==> always nil
[dataEntered setCurrent_model:[fetchedResultsController objectAtIndexPath:indexPath]]; // the same, always nil
what I'm doing wrong ?????
thanks,
r.
edit:
You're right, first I had a to-many relationship, and XCode generated the entity code, that's why after changed the relathionship it still was set as a SET.
Now I've re-generated the entity, and now I have the property like this:
@property (nonatomic, retain) CarModel * current_car_model;
But I'm still getting the same problem.
Now, I've added the inverse relathionship and re-generated the entities. Both entities hav a TO-One relationship. Still having the same problem.
Ok, another try: The relathionship from model to DataEntered is now To-Many. The entites are regenerated again, and now the model is assigned with:
Model *model = [fetchedResultsController objectAtIndexPath:indexPath];
[dataEntered addCurrent_modelObject:model];
And the very last, both relathions are to-many. The same problem exists.
But what I don't understand is why I have to have an inverse relation in this case.
To resume: how I have to define my relations in this case ?
DataEntered can have only ONE Model.
Each Model can be related into many DataEntered.
In an SQL database definition, a field with the id of the model stored in a simple longint field in the DataEntered would be enough. When the relathion is to-many I can't see the field in the .sqlite database, now that I've changed again into To-One, I can see the current_model field as integer. But again, I have in the Model table a field with the related DataEntered, and I think this is wrong, as I'm not going to store Nothing here.
Any light would be appreciated ...
:-)
thanks .....
r.