« Return to Thread: Many to Many GORM join table issue

Many to Many GORM join table issue

by smayzak :: Rate this Message:

Reply to Author | View in Thread

I have a m-m relationship mapped like so:

class Product{
    static hasMany = [categories:Category]
   ...other fields here
}

class Category{
    static hasMany = [products:Product]
    static belongsTo = Product
    ....other fields here
}

This creates 3 tables (names not exact)
Product
Product_Categories
Category

The problem is that when I associate a product with a category by doing this:
product.addToCateogries(Category.get(1)) //or something similar
product.save()

the Product_categories table gets the IDs in the wrong column.  The Product id goes into the category_id column and vice versa.

Any ideas?  I am not sure what I am doing wrong here...

Thanks,
Steve

 « Return to Thread: Many to Many GORM join table issue

LightInTheBox - Buy quality products at wholesale price