Quantcast

Adding fields to a many-to-many join table

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Adding fields to a many-to-many join table

Srdan Dukic
Hi,

i am creating an e-commerce site and have the following domain models:

Customer
CustomerOrder
Product

The relationship between CustomerOrder and Product is a many to many, creating a product_customer_order join table with two foreign keys.

My problem is that I would like to add a field to this join table called 'quantity' to represent the amount of each product that the customer ordered. How would I do this in Grails?

Thank you
--
Srđan Đukić
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding fields to a many-to-many join table

burtbeckwith

There's no direct way, but you can map the join table with a domain class (and add whatever fields you want) and replace the GORM many-to-many with two one-to-many relationships. See http://www.grails.org/Many-to-Many+Mapping+without+Hibernate+XML for one approach.

Burt

> Hi,

>

> i am creating an e-commerce site and have the following domain models:

>

> Customer

> CustomerOrder

> Product

>

> The relationship between CustomerOrder and Product is a many to many,

> creating a product_customer_order join table with two foreign keys.

>

> My problem is that I would like to add a field to this join table called

> 'quantity' to represent the amount of each product that the customer

> ordered. How would I do this in Grails?

>

> Thank you

>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding fields to a many-to-many join table

Alberto Barcelos
In reply to this post by Srdan Dukic
What do you think of creating a object that associate CostumerOrder
and Product and has quantity property? You can make the id composite
of both objects and add any behaviour you want to the association.
Besides you could map the object to the database any way you want,
that is you can make the association object behave like your join
table.

Att.

Alberto Barcelos

On Jan 4, 2011, at 8:18 PM, Srdan Dukic <[hidden email]> wrote:

> Hi,
>
> i am creating an e-commerce site and have the following domain models:
>
> Customer
> CustomerOrder
> Product
>
> The relationship between CustomerOrder and Product is a many to many, creating a product_customer_order join table with two foreign keys.
>
> My problem is that I would like to add a field to this join table called 'quantity' to represent the amount of each product that the customer ordered. How would I do this in Grails?
>
> Thank you
> --
> Srđan Đukić

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...