To do what you want you probably want to set those relationships (ordine and prodotto) to be class properties.

Just a guess, but it looks like what you're trying to model is a line item; it might make more sense if you think about it that way (i.e. order --->> line item ---> product) instead of a many-to-many relationship.

Fez

On Aug 3, 2009, at 11:16 AM, Francesco Romano wrote:

On 03/ago/09, at 18:04, Lachlan Deck wrote:

On 04/08/2009, at 1:39 AM, Francesco Romano wrote:

On 03/ago/09, at 16:10, Lachlan Deck wrote:

On 03/08/2009, at 7:21 PM, Francesco Romano wrote:

Hi..
I'm having some problem with a many-to-many relationship.
I've two entities: Order and Product.
They have a many-to-many relationship, and an attribute: quantity.
The strange thing is that I don't see the OrderProduct model generated...

Check the value of Class Name in the model. It's probably EOGenericRecord. Change it to you.model.OrderProduct

You are right.. Now I see the class


Well.. to be honest I don't understand how many-to-many works... (In WO.. I know the "DB-theory")...

OrderProduct orderProduct = (OrderProduct)EOUtilities.createAndInsertInstance(ec, OrderProduct.ENTITY_NAME);
// or
OrderProduct orderProduct = OrderProduct.createOrderProduct(ec, product, order);
orderProduct.setQuantity(quantity);

ec.saveChanges();

Little problem.. the only method createOrderProduct has as arguments: editingContext, quantity.

1) Your OrderProduct should (usually) have a compound primary key. (orderID, productID). Both keys shouldn't allow null. Both relationships (order, product) should be manditory. Then regenerate your class.

I attach an image..  it's the OrderProduct entity.
<Picture 1.png>

So.. I can't set it's pks.

2) This is good. :-) You're dealing with objects now, not database artifacts like pks and foreign keys. You'll be setting object relationships not pk/fk relationships.

Simply fetch the product/order _objects_ and
orderProduct.setOrder(order);
orderProduct.setProduct(product);


With pks I meant that I don't have the setProduct and setOrder method (and in the constructor).

with regards,
--

Lachlan Deck


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/listfez%40dakri.com

This email sent to list...@dakri.com

--
Faizel Dakri




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to