Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model in multiple collections #517

Open
jmcgdz opened this issue Jan 31, 2015 · 4 comments
Open

Model in multiple collections #517

jmcgdz opened this issue Jan 31, 2015 · 4 comments
Labels

Comments

@jmcgdz
Copy link

jmcgdz commented Jan 31, 2015

I know there has been a lot of talk around this, but I cannot find a solution for my situation.

I'm not sure if I'm using bb relational as it was intended.

My use case is:

[
  {
    "id": "dashboard_container_uuid_1",
    "dashboards": [
      {
        "id": "dashboard_uuid_1",
        "widgets": []
      },
      {
        "id": "dashboard_uuid_2",
        "widgets": []
      }
    ]
  },
  {
    "id": "dashboard_container_uuid_2",
    "dashboards": [
      {
        "id": "dashboard_uuid_3",
        "widgets": []
      },
      {
        "id": "dashboard_uuid_4",
        "widgets": []
      }
    ]
  },
  {
    "id": "dashboard_container_uuid_3",
    "dashboards": [
      {
        "id": "dashboard_uuid_2",
        "widgets": []
      },
      {
        "id": "dashboard_uuid_4",
        "widgets": []
      }
    ]
  }
]

And my issue is that the 'dashboard_container_uuid_3' instance has an empty dashboards collection.

I'm assuming this is because it is trying to create duplicate 'dashboard' models since '2' and '4' are already in previous 'dashboard_container', but I can't find a clean solution to make this work.

@philfreo
Copy link
Collaborator

I don't think there should be any problem with this. Want to post your relations code from both models? You may also want to fiddle with the reverseRelations settings http://backbonerelational.org/#relations-reverseRelation

@rodneyrd
Copy link

rodneyrd commented May 7, 2015

@jmcgdz I am actually facing the same problem with nested collections that contain the same model id. Models with same ids aren't duplicated into nested collections.
Still trying to figure out a work around, problably using a many-to-many relation will solve this. Please let me know if you could get it working.

@rodneyrd
Copy link

rodneyrd commented May 7, 2015

@jmcgdz I made it working using a many-to-many relationship. So in your example you can finally have same "dashboard ids" into different "dashboard_container_uuid". Take a look at this fiddle many-to-many relations example that helped me a lot since BB relational doesn't have a proper documentation for it: http://jsfiddle.net/mmacaula/XaESG/2/

@jameshowe
Copy link

I've got a similar problem, in my case the models are going into the different collections but they are being overridden by the first model to be created.

Maybe I'm oversimplifying things here but why can't we just have a flag against a RelationalModel that determines whether or not we want it to be cached? e.g.

DuplicateModel = new Backbone.RelationalModel.extend({
    singleton: false // don't cache
});

This would help me a lot as for the most part I am only using BBR for the sub-model type binding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants