Grails JIRA

  • Log In Access more options
    • Online Help
    • GreenHopper Help
    • Agile Answers
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Agile
Grails
  • Grails
  • GRAILS-3396 Top level task: GORM Improvements
  • GRAILS-2580

Many-to-Many Overhaul

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0
  • Fix Version/s: 1.1-beta1
  • Component/s: Persistence
  • Labels:
    None

Description

Implementation Recommendations...

1) New syntax for the hasMany definition that allows multiple M2M relationships. Addition of a 'join' attribute that identifies the name of the relationship in the other DO. It would be ideal if 'join' was optional for DOs with only a single M2M relationship.
2) Join table is named based on the singularized concatonation of the two relationship names. The relationship name from the owning DO should be first.
3) FKs should be table + "_" + id.

There is a challange in that many databases limit table and column names to a certan number of characters (I believe in the case of Oracle it's 30).

Example:

class Book {
    static hasMany [authors:[object:Person, join:books],
    publishers:[object:Person, join:publishedBooks]]
    static belongsTo = Person
}

class Person {
    static hasMany [books:[object:Book, join:authors],
    publishedBooks:[object:Book, join:publishers]]
}

This would generate 4 tables. 2 base DO tables (BOOK, PERSON) and 2 join tables (AUTHOR_BOOK, PUBLISHER_PUBLISHED_BOOK). Adding . Let's add some data so that we have the following, one book (book.id= 1) and two authors (person.id = 55 and person.id = 66) and a publisher (person.id = 77).

BOOK

ID NAME
1 Some Book

PERSON

ID NAME
55 Sue
66 Jim
77 Matt

AUTHOR_BOOK

BOOK_ID PERSON_ID
1 55
1 66

PUBLISHER_PUBLISHED_BOOK

BOOK_ID PERSON_ID
1 77

The following SQL would then work...

select book.name, person.name as author
from book, person, author_book
where book.id = author_book.book_id
and person.id = author_book.person_id

...resulting in the following...

NAME AUTHOR
Some Book Sue
Some Book Jim

Activity

  • All
  • Comments
  • Work Log
  • History
  • Activity
  • Git Commits
There are no git log entries for this issue yet.

People

  • Assignee:
    Graeme Rocher
    Reporter:
    Tyler Williams
Vote (16)
Watch (16)

Dates

  • Created:
    03/Mar/08 1:59 PM
    Updated:
    29/Oct/08 8:56 AM
    Resolved:
    29/Oct/08 7:25 AM

Agile

  • View on Board
  • Atlassian JIRA (v5.2.1#813-sha1:277a546)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Grails project. Try JIRA - bug tracking software for your team.