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

Determining existence of relationship without server query #2271

Closed
sandstrom opened this issue Sep 10, 2014 · 7 comments
Closed

Determining existence of relationship without server query #2271

sandstrom opened this issue Sep 10, 2014 · 7 comments

Comments

@sandstrom
Copy link
Contributor

Sometimes it's useful to determine if a relationship is present without querying the server. child.get('mother') will query the server if the mother isn't present.

This private API returns the answer without querying the server !!child._relationships.mother.inverseRecord.

On knowledge of associated records
Mostly, only the 1-side in N-1 and 1-1 relationships will know whether it's associated with another record (given how foreign keys are located). The N-side won't know without querying the server.

Ways to provide this

  1. child.isPresent('mother') return true/false
  2. child.get('mother', { local: true }) return the record if it exists in store, otherwise null
  3. child.count('mother') could return without querying the server for 1-side, and could trigger a server request for the N-side. It's main usage would obviously be remote counting, but that way the API addition would be useful for more than probing for existence.
  4. eachRelationship could be amended to provide info on relationship presence (similar to the current, private, API quoted above).

I think I like (3) the most, but depends on whether others think that's a useful addition. Thoughts?

@sandstrom sandstrom changed the title Determining existence of relationship without querying adapter Determining existence of relationship without server query Sep 10, 2014
@wecc
Copy link
Contributor

wecc commented Nov 14, 2014

Relevant: #2431

@igorT
Copy link
Member

igorT commented May 25, 2015

emberjs/rfcs#57 is aiming to address this

@igorT igorT added the 1.0 label May 25, 2015
@pangratz
Copy link
Member

pangratz commented Jan 2, 2016

I think this issue can be closed since an initial implementation of references has been merged into master. Having the ds-references feature enabled, it can be checked if there is data for a relationship via model.belongsTo("family").value() !== null and model.hasMany("children").value() !== null.

@fivetanley
Copy link
Member

Closing in favor of references!

@sandstrom
Copy link
Contributor Author

If anyone comes across this issue, have a look at #7324 and #7102.

@runspired
Copy link
Contributor

#7796 will add autotracking for this feature

@sandstrom
Copy link
Contributor Author

awesome @runspired

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

6 participants