mekanika / qe

Query envelope (Qe) specification
2 stars 0 forks source link

Populate #1

Closed cayuu closed 9 years ago

cayuu commented 10 years ago

Define a method to illustrate relational data.

cayuu commented 9 years ago

Added in 0.4.0: "populate" - currently in Experimental phase.

cayuu commented 9 years ago

Question of whether (and if so how) to represent "foreign key" references in populate. As at 0.4.0, populate looks as follows:

{ populate: { 'field' : $subqo } }

Given $subqo is a regular Qo, the only foreign reference currently supported is the .resource that the "field" refers to. In this way users.likes may refer to {resource: 'posts'}. Great.

But that leaves a Qo consuming API determining the field/key to "join/associate" on either by:

Both are viable options, but neither cover all use-cases. If the association key is known, it'd be nice to simply stick this in the Qo somewhere. A few options:

  1. inserting a new field in Qo (eg. {associateOn: "assoicate_id"})
  2. overloading an existing field (eg {resource: "users.associate_id"})
  3. sticking it in the meta field (ie. arbitrary data)

None are clear winners. Or perhaps modify the populate object to embed this:

{ populate: {
    field: 'posts',
    key: 'special_id_field',
    query: {limit:20}
  }
}

This seems like the best option.