Two way one to many relationship

Ejaz Ahmed

I have two domain classes one is Game:

class Game {
   String name
   String description
   Double price
   static hasMany = [reviews: Review]
}

and the other one is Review:

class Review {
   String reviewText
   Date reviewDate
   static belongsTo = [game: Game]
}

Both are stripped down versions. I have two objects

r1 = new Review([reviewText: "A game review", reviewDate: new Date()])
g = new Game([name:"Angry Birds", description:"Parabolic physics like game", 20.00])
r1.game=g
r1.save()

After above call is this statement legal?

g.reviews

Will it return a list of all reviews associated with Game? Actually I have an old Grails code which is fetching list of reviews by g.reviews like calls and on Grails 2.4.4, I am getting a null. Was it legal in older versions of Grails? What is the recommended way to fetch reviews associated with a particular game?

dsharew

save with flush:true if you want to immediately access the db.

r1.save(flush:true)

then you can say:

g.reviews

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Laravel - One to Many relationship is not working one way

From Dev

Laravel - One to Many relationship is not working one way

From Dev

Is there a way to simplify a Linq query with a many to one relationship?

From Dev

Is there a way to simplify a Linq query with a many to one relationship?

From Dev

How do you setup the models in Rails 4 for a one to many two way relationship?

From Dev

What is best way to fetch data from two table with one to many relationship?

From Dev

Have two entity in Grails with one to many relationship

From Dev

Query two tables with one to many relationship

From Dev

Many-to-many collection of same entity, with two-way relationship

From Dev

Simplified way to handle one-to-many relationship updates in Entity Framework?

From Dev

Is there a way to select columns using eloquent one to many relationship in laravel 5.2?

From Dev

Joining a table to two one-to-many relationship tables in SQL Server

From Dev

How to query two collections that have a "one-to-many" relationship in MongoDB?

From Dev

one to many relationship entity framework required in two side

From Dev

One To Many Relationship In Firebase

From Dev

Doctrine One to Many relationship

From Dev

Seeding one to many relationship

From Dev

Themeing a one to many relationship

From Dev

One to many relationship table

From Dev

Paginate a One to Many Relationship

From Dev

Laravel: one to many relationship

From Dev

Accessing a one to many relationship

From Dev

Displaying one to many relationship

From Dev

Implementing one to many relationship

From Dev

MagicalRecord: one to many relationship

From Dev

Paginate a One to Many Relationship

From Dev

Seeding one to many relationship

From Dev

One to many relationship with NSfetchedresultscontroller

From Dev

one to many relationship in laravel

Related Related

  1. 1

    Laravel - One to Many relationship is not working one way

  2. 2

    Laravel - One to Many relationship is not working one way

  3. 3

    Is there a way to simplify a Linq query with a many to one relationship?

  4. 4

    Is there a way to simplify a Linq query with a many to one relationship?

  5. 5

    How do you setup the models in Rails 4 for a one to many two way relationship?

  6. 6

    What is best way to fetch data from two table with one to many relationship?

  7. 7

    Have two entity in Grails with one to many relationship

  8. 8

    Query two tables with one to many relationship

  9. 9

    Many-to-many collection of same entity, with two-way relationship

  10. 10

    Simplified way to handle one-to-many relationship updates in Entity Framework?

  11. 11

    Is there a way to select columns using eloquent one to many relationship in laravel 5.2?

  12. 12

    Joining a table to two one-to-many relationship tables in SQL Server

  13. 13

    How to query two collections that have a "one-to-many" relationship in MongoDB?

  14. 14

    one to many relationship entity framework required in two side

  15. 15

    One To Many Relationship In Firebase

  16. 16

    Doctrine One to Many relationship

  17. 17

    Seeding one to many relationship

  18. 18

    Themeing a one to many relationship

  19. 19

    One to many relationship table

  20. 20

    Paginate a One to Many Relationship

  21. 21

    Laravel: one to many relationship

  22. 22

    Accessing a one to many relationship

  23. 23

    Displaying one to many relationship

  24. 24

    Implementing one to many relationship

  25. 25

    MagicalRecord: one to many relationship

  26. 26

    Paginate a One to Many Relationship

  27. 27

    Seeding one to many relationship

  28. 28

    One to many relationship with NSfetchedresultscontroller

  29. 29

    one to many relationship in laravel

HotTag

Archive