In grails, I can implement an N:1 relationship like this:
class Parent { hasMany = [children:Child] }
class Child { belongsTo = [parent:Parent] }
Now (if addTo and removeFrom is always properly used) I can get a Parent's children via parent.children.
But I can also do it without hasMany:
class Parent { }
class Child { belongsTo = [parent:Parent] }
Then I have to use Child.findAllByParent(parent) to get all children.
My question: Are there any important reasons why I should use hasMany if can query a parent's children in the second way as well?
I guess that it's sometimes easier (and perhaps faster if eager-fetched together with the parent?) to just refer to parent.children, but on the other hand this List can become rather long when there are several children. And what I don't like about hasMany either is that you always have to take care about the addTo or removeFrom or to clear the session after adding a new Child with a Parent so that grails does this automatically...
Is the answer that you should simply use hasMany if there are few children and don't use it if there are many (for performance reasons), or is there more behind it?