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

Accessing meta-information on associations #177

Closed
ghost opened this issue Mar 26, 2012 · 4 comments
Closed

Accessing meta-information on associations #177

ghost opened this issue Mar 26, 2012 · 4 comments
Labels
🏷️ feat This PR introduces a new feature

Comments

@ghost
Copy link

ghost commented Mar 26, 2012

One thing that would be useful is to be able to access meta information on associated objects. Here's an example of a use case:

Let's say that I have a Todo list with a list of Actions. Each Action hasMany Comments. I would like to find out how many comments an action has without loading the association and also find out whether the association has been loaded to determine whether I'm showing a collapsed or expanded comments view.

This would let me have a view that looks like this:

My cool action title!!!

  • View 3 comments

My cool action title!!
comment 1
comment 2
comment 3

App.Action = DS.Model.extend({
   comments: DS.hasMany('App.Comment');
})

App.Comment = DS.Model.extend({
  body: DS.attr('string');
});

// Example request
a=App.store.findAll(App.Action);

// Response
{actions: [
 {"id":0 comment_ids: [123,456,321] }, ...
]

// This is what I'd like to be able to do
a.comments.isLoaded();   // or a.get('comments.isLoaded')
  => false
a.comments.count();  // or a.get('comments.count')
  => 3

a.get('comments');
 => // triggers a load request and returns an array of comments

a.comments.isLoaded();
  => true   // because the associated objects have been loaded

Hope this makes sense!

@ppcano
Copy link
Contributor

ppcano commented Apr 11, 2012

+1, to provide a simple way to be notified when a list of items has been loaded either by callback functions or any binding to a property. This could be applied for associations and modelArrays.

@wagenet
Copy link
Member

wagenet commented Apr 18, 2012

Duplicate of #83.

@wagenet wagenet closed this as completed Apr 18, 2012
@ppcano
Copy link
Contributor

ppcano commented Apr 18, 2012

@wagenet , peter you closed all the associated issues #83, and #190. is there already an implemented solution for this issue??

@wagenet
Copy link
Member

wagenet commented Apr 18, 2012

#83 is not closed.

@runspired runspired added 🏷️ feat This PR introduces a new feature and removed Improvement labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ feat This PR introduces a new feature
Projects
None yet
Development

No branches or pull requests

3 participants