Closed danfinlay closed 10 years ago
Yes, I just posted the link of the other thread for what we call "reflexive associations" in the tests:
https://github.com/geddy/model/blob/master/test/integration/adapters/shared.js#L948
That's interesting, I'm surprised I don't see the inverse relationship declared, a 'getParent', maybe?
What does the adapter expect in this situation? Children have a child_id
column?
There's a Friendship join-model: https://github.com/geddy/model/blob/master/test/fixtures/person.js#L11
I figured the Friendship model was to enable many-to-many relationships. I definitely could do this, though, it's not that bad, but it seems like it should be unnecessary for a one-to-many, the way a reply comment is in a recursive comment system (each comment can only belong to a single comment).
Oh, duh, yes. That's a different example, I'm sorry. So yes, it would be the Children association:
https://github.com/geddy/model/blob/master/test/fixtures/person.js#L13
The adapter looks for child_person_id, since it's named association. We use the name as a prefix for the actual model name.
Simple! Thanks!
Curious if anyone has gotten this working, or if it's a feature that would be nice to add:
Being able to set up recursive relationships (like a threaded comment system, where each comment has a parent comment), where a comment can be eagerly loaded with its children.