Maybe (hope) the last thing:

This is my model (right now only on paper..)
Product <->> LineItem <<->Cart
Cart <<-> Customer
Cart <-> Order
Customer <->> Order

So.. the tables should be:

Product (...)
Customer (...)
LineItem (... , ProdID, CartID) (Foreign keys to Product.id and Cart.id, mandatory) Cart (... , CustomerID*) (Foreign Key to Customer.id, optional because used only if the customer saves the cart) Order (... , CustomerID, CartID) (Foreign keys to Customer.id and Cart.id, mandatory)

Now.. The problem is that I can't do a one-to-one relationship between Cart and Order. I want Order to have the foreign key (an order must have a cart, but a cart could not have an order if it is saved - using the customer relationship) But.. using the UI I can't make a one-to-one.. so I create a one-to- many putting the foreign key field in order. Than I changed in the cart entity the relationship with order to a to- one and optional but I have this warning:

The relationship order is optional but the attribute id does not allow nulls.

I'm a bit confused... in a "relational" way it should work.. but here in WO??

Thanks

On 04/ago/09, at 15:16, Francesco Romano wrote:

And.. if I change to this ?

Product <->> LineItem <<-> Cart

And Cart is linked to:
Cart <<-> Customer
Cart <-> Order

The customer and order foreign keys are both optional and both inside the Cart Entity. So.. if a user want to save a cart (and not place an order) I link the cart directly to a customer. If the user want to place the order, the cart is linked to the order and unlinked from the customer (this because Order <<-> Customer)


What do you think? Can this be correct?

Francesco

On 04/ago/09, at 11:32, Amedeo Mantica wrote:


On 03/ago/09, at 19:45, Francesco Romano wrote:

Ok.. I'll postpone this,,

Now.. for the model I was thinking at this:

Order <->> LineItem(has quantity as attribute) << - >Product
This should solve the to-many problem..

To save the cart... I thought to:
Customer <->> LineItem
Or:
Customer <-> Cart <->> LineItem
(Cart entity is useless, but I can add a LastUpdated date ...)

What do you think?


as a first rapid look seem to be ok
Ciao
Amedeo

On 03/ago/09, at 19:02, Amedeo Mantica wrote:

you can do it via webobjects but is a bit "hard"

is more easy to do a call to a directaction using "curl" sheduled via launchd or cron

Regards
Amedeo

On 03/ago/09, at 18:51, Francesco Romano wrote:

On 03/ago/09, at 18:49, Amedeo Mantica wrote:


On 03/ago/09, at 18:40, Francesco Romano wrote:


On 03/ago/09, at 18:29, Amedeo Mantica wrote:

why do you want to put the quantity in that table ???

leave the relationship alone

create a table " cart " with a relationship to product and a column quantity.

then create a relationship cart to order

Regards
Amedeo


Because I was thinking to save the cart in the cookies.. Should I save the cart of every customer even if they don't place an order? (this is a question.. I don't know how things work..)

yes, so you can give customers choice to save cart and finish order later, if the order is not finished within some days you trash the cart

Amedeo

Yeah.. I have to change the model a bit :p
Btw.. how can I trash the cart automatically? Is it possible with WO?


Francesco
On 03/ago/09, at 18:16, 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 ([email protected] )
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/amedeomailing%40insigno.it

This email sent to [email protected]





_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/amedeomailing%40insigno.it

This email sent to [email protected]



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/amedeomailing%40insigno.it

This email sent to [email protected]




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

This email sent to [email protected]

Reply via email to