In my case I've got "Tasks" and "Users" with a middle class of "Participants" but I have adapted a JS Fiddle for the users/memberships/groups similar to the examples.
I want to run a server query for new tasks, when the query returns it will only contain user id's, without the full user model. Then, after the server finishes returning all of the tasks, I want to trigger a second server request for all users which I don't have the full model.
Example: I may receive 30 tasks, each task with 3 users, for 150 users, but only perhaps 50 unique users, of which I may already know about 40 of them, so I'd query for the remaining 10 as opposed to receiving 150 blocks of full user data.
To do this, after I run the task request, I want to dive into the user model, and do some stuff, but after working on this for a while, I realized that my User collection wasn't being used!! I tried adding collection: Users on the user model, but Supermodel still didn't seem to pick up the collection, but rather creates it's own collection internally. (The "one" part of the middle relationship.
From time to time I want to be able to directly interface with the users collection, so I don't want to go through User.all(), additionally, I have declared a url on my Users collection to be used sometimes when receiving users that are completely unrelated to tasks.
You should see in the fiddle that the Membership.has().one(...) chain (the middle part of many-to-many) fails to allow a collection, and fails to trigger the Groups.model create function.
It seems the solution might be to source from the model.collection if defined instead of new Backbone.Collection, or allow a collection parameter in the relationship... but I guess that wouldn't work since it's not the actual instance. I guess we could initialize the collection previously, then pass it in to the relationship declaration, but that's odd too. I'm not sure the solution for this. Is there something I'm missing?
In my case I've got "Tasks" and "Users" with a middle class of "Participants" but I have adapted a JS Fiddle for the users/memberships/groups similar to the examples.
http://jsfiddle.net/4GGCk/10/
Let me explain my initial goal(s):
I want to run a server query for new tasks, when the query returns it will only contain user id's, without the full user model. Then, after the server finishes returning all of the tasks, I want to trigger a second server request for all users which I don't have the full model.
Example: I may receive 30 tasks, each task with 3 users, for 150 users, but only perhaps 50 unique users, of which I may already know about 40 of them, so I'd query for the remaining 10 as opposed to receiving 150 blocks of full user data.
To do this, after I run the task request, I want to dive into the user model, and do some stuff, but after working on this for a while, I realized that my User collection wasn't being used!! I tried adding collection: Users on the user model, but Supermodel still didn't seem to pick up the collection, but rather creates it's own collection internally. (The "one" part of the middle relationship.
You should see in the fiddle that the Membership.has().one(...) chain (the middle part of many-to-many) fails to allow a collection, and fails to trigger the Groups.model create function.
It seems the solution might be to source from the model.collection if defined instead of new Backbone.Collection, or allow a collection parameter in the relationship... but I guess that wouldn't work since it's not the actual instance. I guess we could initialize the collection previously, then pass it in to the relationship declaration, but that's odd too. I'm not sure the solution for this. Is there something I'm missing?