Skip to content
This repository was archived by the owner on Mar 18, 2021. It is now read-only.
This repository was archived by the owner on Mar 18, 2021. It is now read-only.

Populate sub-objects in fetch request #26

Closed

Description

@anachlas
No description provided.

Activity

  1. itsjoeconway commented on Jan 6, 2016

    @itsjoeconway
    Contributor

    at one point, was implemented but it was a bit confusing and the rules were a bit unclear. so we can take another look at this soon.

    note that it'd be nice to have auto-generated async accessors for sub-objects instead of having to build the query ourselves

  2. itsjoeconway commented on Jan 15, 2016

    @itsjoeconway
    Contributor

    Just to start the convo, something like this:

    var categoryTemplate = new Category();
    var roomTemplate = new Room()..categories = [categoryTemplate];
    var userTemplate = new User()..id = 1..rooms = [roomTemplate];
    
    var users = await adapt.populateModelGraph(userTemplate);
    

    Where users contains all users that have id = 1 (which we know to just be one for this particular value), and its properties will be populated, along with all of its rooms, and all of the rooms will have all of their categories.

    Every property set on these objects would become filters (just like predicateObjects). An empty object in a relationship (or list of objects) indicates that you want them fetched.

    Now, I really don't like this whole using model objects as templates for generating predicates, but its an OK temporary solution. Where it breaks down is when you need anything other than equality (<, >, like, etc.). What I'd really want is an automatically generated class for each model class. The auto generated class would have the same properties as the model class, except the properties would be a different type. Maybe some sort of PredicateMatcher. Its values could follow the Matcher syntax like in tests:

    var userTemplate = new PredicateMatcher<User>();
    userTemplate.name = beginsWith("B");
    userTemplate.rooms.items = hasLength(10); // rooms is lazily allocated
    
    var query = userTemplate.query;
    var modelGraph = await query.fetch(adapter);
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions