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

[rfcs] - knowing when records are loaded or not #2431

Closed
fivetanley opened this issue Oct 29, 2014 · 5 comments
Closed

[rfcs] - knowing when records are loaded or not #2431

fivetanley opened this issue Oct 29, 2014 · 5 comments

Comments

@fivetanley
Copy link
Member

When people are trying to check for contains/etc. See if the relationship has been loaded without asking the server for the records. There is currently no API for this.

An example: has the post loaded its comments? if not I may want to make a different kind of query

What are the comment IDs? I may have not yet loaded the comments but I want to know their IDs without telling the server to load them.

We would like contributors to use this issue for use cases.

@aaronbhansen
Copy link

We have a few situations we need to filter or check a relation based on the id, but don't need the entire relation loaded. One example of how we are using this is in the gist. This isn't related as much as to knowing if the records are loaded, but more towards the second part of your issue, knowing the id without requesting the full data from the server.

https://gist.github.com/aaronbhansen/078c14ac65df6985bcd4

We might change our workflow depending on if we knew records were loaded or not, but since there hasn't been an easy way to do this so far, I don't have any code examples for your first half of the issue.

@sandstrom
Copy link
Contributor

This is copied from another issue (#2271), on determining relationship presence (somewhat related).


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 works 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.

@igorT
Copy link
Member

igorT commented May 25, 2015

emberjs/rfcs#57 is aiming to address this

@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 Author

@pangratz thank you!

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

5 participants