createAndInsert from a directAction App
createAndInsert from a directAction App
- Subject: createAndInsert from a directAction App
- From: "Jonathan Fleming" <email@hidden>
- Date: Fri, 17 Oct 2003 08:24:16 +0100
G'day DevHeads
I'm still not clued up on how to use takeValueForKey methods properly I have
a fair idea but obviously not good enough to overcome this problem(which you
might just tell me is real simple to solve).
Right then, I have two tables/entities on is a user entity called
TbAdminUser and the other is TbAdminUserAddress and the relationships to
each other is:
TbAdminUser (toOne)> tbAdminUserAddress no back relationship.
Now since I am trying to populate the database from a directAction i have to
use these methods you see in the code below, however, when i do my save
everything seems fine except only the TbAdminUser table/entity is being
populated with the information from the variables/keys. The
TbAdminUserAddress detaisl are lost, they are simply not geting to the
database.
I feel this has something to do with me maybe not using the
createAndInsertInstance method correctly. Or possibly missing an additional
method or statement.
Can anyone offer a solution
Much appreciation
Jonathan:^)
Here's the code i'm using:
if/*5*/ ( tbAdminUserList.count() == 1 ) {
NSLog.out.appendln("\n*** last array object is:
" + tbAdminUserList.lastObject() + "\n");
return registeredUserExists();
}
else if ( tbAdminUserList.count() == 0 )
{
NSLog.out.appendln("\n*** else value for this
user = " + tbAdminUserList + "\n");
// lock ec
editingContext.lock();
// create user
EOEnterpriseObject user =
EOUtilities.createAndInsertInstance(editingContext, "TbAdminUser");
NSLog.out.appendln("\n*** user created: " + user
+ "\n");
// set values
user.takeValueForKey(companyName,
"companyName");
user.takeValueForKey(firstName, "firstName");
user.takeValueForKey(lastName, "lastName");
user.takeValueForKey(loginName, "loginName");
user.takeValueForKey(password1, "entry");
user.takeValueForKey(tradeStatus,
"tradeStatus");
user.takeValueForKey(metaDescription,
"metaDescription");
user.takeValueForKey(metaKeywords,
"metaKeywords");
user.takeValueForKeyPath(addressLine1,
"tbAddress.addressLine1");
user.takeValueForKeyPath(addressLine2,
"tbAddress.addressLine2");
user.takeValueForKeyPath(cityTown,
"tbAddress.cityTown");
user.takeValueForKeyPath(county,
"tbAddress.county");
user.takeValueForKeyPath(postcode,
"tbAddress.postcode");
user.takeValueForKeyPath(country,
"tbAddress.country");
user.takeValueForKeyPath(tel1,
"tbAddress.tel1");
user.takeValueForKeyPath(tel1Ext,
"tbAddress.tel1Ext");
user.takeValueForKeyPath(tel2,
"tbAddress.tel2");
user.takeValueForKeyPath(tel2Ext,
"tbAddress.tel2Ext");
user.takeValueForKeyPath(fax1,
"tbAddress.fax1");
user.takeValueForKeyPath(fax2,
"tbAddress.fax2");
user.takeValueForKeyPath(cellular,
"tbAddress.cellular");
user.takeValueForKeyPath(url, "tbAddress.url");
user.takeValueForKeyPath(url,
"tbAddress.UrlName");
user.takeValueForKeyPath(email1,
"tbAddress.email1");
user.takeValueForKeyPath(email2,
"tbAddress.email2");
EOEnterpriseObject tbAddressAdminUser =
EOUtilities.objectMatchingKeyAndValue(editingContext, "TbAddressAdminUser",
"email1", email1);
NSLog.out.appendln("\n*** tbAddressAdminUser
created: " + tbAddressAdminUser + "\n");
user.addObjectToBothSidesOfRelationshipWithKey(tbAddressAdminUser,
"tbAddress");
// save changes
editingContext.saveChanges();
// unlock ec
editingContext.unlock();
return pageWithName("AdminPanel");
}
else /*6*/
{
// Bad news, the database contains multiple
users!
NSLog.out.appendln("\n*** multiples of this user
exists: " + tbAdminUserList + "\n");
return multipleUserExistsAction();
}
_________________________________________________________________
Sign-up for a FREE BT Broadband connection today!
http://www.msn.co.uk/specials/btbroadband
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.