[baseten-users] Dictionary for creating new objects
Erik Aderstedt
erik at aderstedt.se
Thu May 7 11:12:54 EEST 2009
Hi!
When creating a new object with an entity thats on the many side of a
one-to-many relationship, I set up a dictionary like so:
BXDatabaseObject *customer;
/* .. customer is set up .. */
NSDictionary *fieldValues = [NSDictionary dictionaryWithObjectsAndKeys:
customer, @"customer", /* customer is the foreign key constraint, and
"Customer" is the entity on the "one" side of the relationship */
.. other fields ..
,nil];
BXDatabaseObject *license = [ctx createObjectForEntity:[ctx
entityForTable:@"License" error:&error] withFieldValues:fieldValues
error:&error];
With the above code the createObjectForEntity call throws an exception:
-[NSCFDictionary setObject:forKey:]: attempt to insert nil key
No "license" object is inserted. I'm not clear on why this fails. The
workaround is simple:
fieldValues = [NSDictionary dictionaryWithObjectsAndKeys:
[customer valueForKey:@"id"], @"customer_id",
... other fields ..
, nil];
but it feels less elegant than the first solution. Is the error due to
a bug in BaseTen (I'm using 1.6.2) or is it just not the way to do it?
Coming from a Core Data background, the first approach seems natural...
Cheers,
Erik Aderstedt
Aderstedt Software AB
More information about the baseten-users
mailing list