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

Add a related model subquery API #54

Open
ghost opened this issue Jan 14, 2015 · 1 comment
Open

Add a related model subquery API #54

ghost opened this issue Jan 14, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 14, 2015

As regards subqueries, I have already set up instance methods on my models that will go out and grab related records. I am injecting them automatically by parsing my model pseudo-code as such:

model User:
{
  hashKey: 'id',
  schema: {
    id: vogels.types.uuid(),
    orders: vogels.types.stringSet()
  }
}

model Order:
{
  hashKey: 'id',
  schema: {
    id: vogels.types.uuid(),
    user: Joi.string()
  }
}    

In this case I'd store the id attribute from each related order in the Users model instance 'orders' set, then use Order.getItems() to query the orders back out by their keys rather than scanning the whole Order table looking for a user id that matched or building global secondary indexes on that attribute.

Right now when I create my models I inject getters for the related data into Model.prototype. This works fine for lazy loading, but sometimes I want to make a single query and get back related model instances already included in a model instance substructure that lets me interact with them against the other model's API.

So basically, I have lazy loading solved, but I need a solution similar to how you roll up multiple queries into a single response to get around dynamo's max records in a resultset restriction, except synthesizing results from a subquery to another table rather than aggregating results for multiple queries on the same table.

@ghost ghost mentioned this issue Jan 14, 2015
@justhamade
Copy link

@keithchilders could you provide an example of your lazy loading instance methods?

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

1 participant