RE: createAndInsert from a directAction App
RE: createAndInsert from a directAction App
- Subject: RE: createAndInsert from a directAction App
- From: "Pierre Bernard" <email@hidden>
- Date: Fri, 17 Oct 2003 09:38:51 +0200
- Thread-topic: createAndInsert from a directAction App
Jonathan,
By using a keyPath like tbAddress.email2 you are modifying the TbAdminUserAddress object at the destination of the tbAdress relationship before replacing that whole object when you do the addToBothSidesOfRelationshipWithKey:tbAddress
Moreover that relationship is likely to be empty unless you have populated it in awakeFromInsertion. Thus all values you set using a keyPath beginning with tbAddress have no place to go.
Try setting the tbAddress relationship before modifying attributes in the object it refers to.
Pierre
--
Got a hang for movies?
http://homepage.mac.com/I_love_my/movies.html
-----Original Message-----
From: Jonathan Fleming [mailto:email@hidden]
Sent: Friday, October 17, 2003 9:24 AM
To: email@hidden; email@hidden
Subject: createAndInsert from a directAction App
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.
**********************************************************************
This email and any files transmitted with it are intended solely for
the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the sender
of this message. (email@hidden)
This email message has been checked for the presence of computer
viruses; however this protection does not ensure this message is
virus free.
Banque centrale du Luxembourg; Tel ++352-4774-1; http://www.bcl.lu
**********************************************************************
_______________________________________________
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.