Grails hasOne vs. belongsTo

前端 未结 1 2001
挽巷
挽巷 2021-01-12 09:22

To create one-to-one relationships in Grails I can do:

class Person {
    static hasOne = [address: Address]
}

In this case the Address ta

相关标签:
1条回答
  • 2021-01-12 09:57

    hasOne indicates that there is a bi-directional one-to-one relationship where the child table has the parent's foreign key, as in your example.

    belongsTo is used to control cascades by indicating that the class belongs to the specified class. In your example, deleting a given Person would cascade the delete to any associated Addresses.

    0 讨论(0)
提交回复
热议问题