one-to-many with self not working

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

one-to-many with self not working

Jonathan Carlson
I'm having trouble getting a one-to-many relationship with self to work.
 The children set is always empty.

I recreated the problem using the Book/Author example so I hope you,
Graeme, or someone else can try it to prove I'm not crazy ;-).  I think
these classes are all you need to see the issue (Oh, you'll need
scaffolded controllers too).  "The Shining" is the parent of "Fox in
Sox" but shows no children as it seems it should:

class Book {
    @Property Long id
    @Property Long version

    @Property relatesToMany = [children : Book.class]

    @Property String title
    @Property Author author
    @Property Book parent    
    @Property Set children = new HashSet()
   
    def addChild(Book b) {
      b.parent = this
      children.add(b)
      System.out.println "************** Adding child ${b} to ${this}"
    }
   
    String toString() { return title }    
}
========================================
class Author {
    @Property Long id
    @Property Long version

    @Property relatesToMany = [books : Book.class]

    @Property String name
    @Property Set books = new HashSet()
   
    def addBook(book) {
      book.author = this
      books.add(book)
    }
   
    String toString() { return name }
}
========================================
class ApplicationBootStrap {

  @Property Closure init = { servletContext ->
    def a = new Author(name:"Stephen King")
    def b = new Book(title:"The Shining")
    def b2 = new Book(title:"Fox in Sox")
    a.addBook(b)
    a.addBook(b2)        
    b.addChild(b2)
    a.save()
  }
 
  @Property Closure destroy = {
  }
 
}



______________________________________________________________________
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

Katun Corporation -- www.katun.com
_____________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: one-to-many with self not working

graemer
Jonathan,

are you working against the latest CVS head? I fixed this issue a few
days ago as i was having a similar problem

Cheers
Graeme

On 3/27/06, Jonathan Carlson <[hidden email]> wrote:

> I'm having trouble getting a one-to-many relationship with self to work.
>  The children set is always empty.
>
> I recreated the problem using the Book/Author example so I hope you,
> Graeme, or someone else can try it to prove I'm not crazy ;-).  I think
> these classes are all you need to see the issue (Oh, you'll need
> scaffolded controllers too).  "The Shining" is the parent of "Fox in
> Sox" but shows no children as it seems it should:
>
> class Book {
>     @Property Long id
>     @Property Long version
>
>     @Property relatesToMany = [children : Book.class]
>
>     @Property String title
>     @Property Author author
>     @Property Book parent
>     @Property Set children = new HashSet()
>
>     def addChild(Book b) {
>       b.parent = this
>       children.add(b)
>       System.out.println "************** Adding child ${b} to ${this}"
>     }
>
>     String toString() { return title }
> }
> ========================================
> class Author {
>     @Property Long id
>     @Property Long version
>
>     @Property relatesToMany = [books : Book.class]
>
>     @Property String name
>     @Property Set books = new HashSet()
>
>     def addBook(book) {
>       book.author = this
>       books.add(book)
>     }
>
>     String toString() { return name }
> }
> ========================================
> class ApplicationBootStrap {
>
>   @Property Closure init = { servletContext ->
>     def a = new Author(name:"Stephen King")
>     def b = new Book(title:"The Shining")
>     def b2 = new Book(title:"Fox in Sox")
>     a.addBook(b)
>     a.addBook(b2)
>     b.addChild(b2)
>     a.save()
>   }
>
>   @Property Closure destroy = {
>   }
>
> }
>
>
>
> ______________________________________________________________________
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please notify
> the system manager.
>
> Katun Corporation -- www.katun.com
> _____________________________________________________________________
>
Reply | Threaded
Open this post in threaded view
|

Re: one-to-many with self not working

Jonathan Carlson
In reply to this post by Jonathan Carlson
Doh, I should have updated with CVS code right away when I had a
problem.  Thanks for being one step ahead of me!



>>> [hidden email] 2006-03-27 11:37:23 PM >>>
Jonathan,

are you working against the latest CVS head? I fixed this issue a few
days ago as i was having a similar problem

Cheers
Graeme

On 3/27/06, Jonathan Carlson <[hidden email]> wrote:
> I'm having trouble getting a one-to-many relationship with self to
work.
>  The children set is always empty.
>
> I recreated the problem using the Book/Author example so I hope you,
> Graeme, or someone else can try it to prove I'm not crazy ;-).  I
think

> these classes are all you need to see the issue (Oh, you'll need
> scaffolded controllers too).  "The Shining" is the parent of "Fox in
> Sox" but shows no children as it seems it should:
>
> class Book {
>     @Property Long id
>     @Property Long version
>
>     @Property relatesToMany = [children : Book.class]
>
>     @Property String title
>     @Property Author author
>     @Property Book parent
>     @Property Set children = new HashSet()
>
>     def addChild(Book b) {
>       b.parent = this
>       children.add(b)
>       System.out.println "************** Adding child ${b} to
${this}"

>     }
>
>     String toString() { return title }
> }
> ========================================
> class Author {
>     @Property Long id
>     @Property Long version
>
>     @Property relatesToMany = [books : Book.class]
>
>     @Property String name
>     @Property Set books = new HashSet()
>
>     def addBook(book) {
>       book.author = this
>       books.add(book)
>     }
>
>     String toString() { return name }
> }
> ========================================
> class ApplicationBootStrap {
>
>   @Property Closure init = { servletContext ->
>     def a = new Author(name:"Stephen King")
>     def b = new Book(title:"The Shining")
>     def b2 = new Book(title:"Fox in Sox")
>     a.addBook(b)
>     a.addBook(b2)
>     b.addChild(b2)
>     a.save()
>   }
>
>   @Property Closure destroy = {
>   }
>
> }
>
>
>
>
______________________________________________________________________
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please
notify
> the system manager.
>
> Katun Corporation -- www.katun.com
>
_____________________________________________________________________
>

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

______________________________________________________________________
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

Katun Corporation -- www.katun.com
_____________________________________________________________________