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

findOrCreate(id) doesn't create #401

Closed
CodeMonkeySteve opened this issue Sep 14, 2013 · 1 comment
Closed

findOrCreate(id) doesn't create #401

CodeMonkeySteve opened this issue Sep 14, 2013 · 1 comment

Comments

@CodeMonkeySteve
Copy link

I have an Organization model which has many Person models, where Person defines organization_id:

class @Organization extends Backbone.RelationalModel
  relations: [
    relatedModel: 'Person'
    type: Backbone.HasMany
    key: 'people'
    keyDestination: 'people_attributes'
    keySource: 'people'
    parse: true
    reverseRelation:
      key: 'organization'
      keySource: 'organization_id'
  ]

But if I instantiate a Person before the related Organization, the Organization model is never created. E.g.:

new Person({organization_id: 42}).get('organization') == null

I've tracked this down to the fact that findOrCreate returns null when an id is passed but the model does not (yet) exist in the store. I would expect it to create a sparse model (i.e. just an id), suitable for fetching.

I've tried modifying findOrCreate to add this behavior, but apparently lots of things expect the existing behavior (i.e. all the tests broke).

@CodeMonkeySteve
Copy link
Author

Of course, 4 minutes after I created this I realized that it's a duplicate of #399.

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

No branches or pull requests

2 participants