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

Relations between models #40

Closed
fbuchinger opened this issue Oct 28, 2010 · 1 comment
Closed

Relations between models #40

fbuchinger opened this issue Oct 28, 2010 · 1 comment
Labels

Comments

@fbuchinger
Copy link

How can I specify relations between models and query them? Take a simple tagging application as an example: you have one model representing your main entity (source code snippet, photo, comment etc) and one model representing a tag.

How can I query all main entities that have a certain tag assigned? Or all entities without tag?

@jashkenas
Copy link
Owner

Querying logic is part of the interface with your application -- there are a number of ways you can handle it:

  • Change the url() that the Collection returns to include your current search query. The next time you fetch() it's models, they'll be replaced by models that match the current search. This is useful for collections that contain search results.

  • Just run your regular jQuery Ajax call, and refresh the collection with the results. This can happen in a method that you add to your collection, like fetchForTag...

    $.getJSON('/photos/tagged/china.json', {}, function(response) {
      Photos.refresh(response);
    });
    
  • If you want to include tags nested in the same response as the photos, you can have your model pull them out, and turn them into Tag objects of their own...

    extractTags : function() {
      this.tags.refresh(this.get('tags'));
    }
    

... just some thoughts.

This issue was closed.
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

2 participants