Re: Adding primary & secondary simultaneously
Re: Adding primary & secondary simultaneously
- Subject: Re: Adding primary & secondary simultaneously
- From: Chuck Hill <email@hidden>
- Date: Tue, 09 Dec 2003 20:49:38 -0800
IMHO, part of your trouble is that you are still trying to think in terms
of tables and keys and not in terms of objects and relationships.
>newClient.addToAddress(newAddress);
>newAddress.setClientId(newClient);
I think what you mean to say is "a client has many addresses and each
address knows the client that it belongs to". So, properly modelled, this
code should read:
newClient.addToAddresses(newAddress); // Note plural addToAddresses
newAddress.setClient(newClient); // Note NOT clientID
Connect the objects, let EOF worry about the gory SQL details. :-)
And, yes, this is better:
newClient.addObjectToBothSidesOfRelationshipWithKey(newAddress, "addresses");
// Note "addresses", not "Address". Use the name of the
// relationship not the name of the entity
I think if you go back to the Authors example and look at your code and
notice what is different between addToBooks and addToAddress and between
setAuthor and setClientID you might see the source of your problem.
Chuck
At 11:04 PM 09/12/2003 -0500, Drew Thoeni wrote:
>I'm trying to add a new record to my client table and, from the same
>form and in the same transaction, add the client's address to a
>separate address table. The address table is a to-many relationship
>from the client table.
>
>Modeling my code after the example in the WO "Web Applications"
>tutorial (below)
>
>TUTORIAL
>author.addToBooks(newBook);
>newBook.setAuthor(author);
>
>MY CODE
>newClient.addToAddress(newAddress);
>newAddress.setClientId(newClient);
>
>I get an error "Register1.java:44: setClientId(java.lang.Number) in
>Address cannot be applied to (Client)"
>
>I have also tried:
>newClient.addObjectToBothSidesOfRelationshipWithKey("Address"); With
>similar results.
>
>
>Can anyone suggest a better example/documentation to work from (other
>than the Web Applications tutorial)? I am assuming it is possible to
>add both sides of a one-to-many relationship from one form (in a
>single trip to the server).
>
>Regards,
>
>Drew
>_______________________________________________
>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.
>
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
_______________________________________________
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.