@knorm/relations
Knorm plugin that adds ability to fetch data from multiple tables via SQL joins.
Documentation
Visit the documentation site.
Relations plugin for @knorm/knorm
Knorm plugin that adds ability to fetch data from multiple tables via SQL joins.
Visit the documentation site.
All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.
Note: Version bump only for package @knorm/relations
Instead of:
const knorm = require('@knorm/knorm');
const knormPostgres = require('@knorm/postgres');
const { Knorm } = knorm;
const { KnormPostgres } = knormPostgres;
Do:
const { knorm, Knorm } = require('@knorm/knorm');
const { knormPostgres, KnormPostgres } = require('@knorm/postgres');
on
field (as a string) doesn't exist (2f575bc)on
as an array (4faab5e)Model.fields = { id: 'integer' };
class User extends Model {}
class Image extends Model {}
Image.fields = {
userId: { type: 'integer', references: User.fields.id }
};
Image.fetch({
// wrong:
// join: User.query.on('userId')
// correct:
join: User.query.on(Image.fields.userId)
});
However, fields on the same model can still be referenced by their string field-name:
User.fetch({ join: Image.query.on('userId') });
JOIN
clause for join
query option (b320cc4)fields: false
on joined queries (a3efbf3)null
. However, if the first
option is configured on the joined query, the empty row is still
returned as null
. This matches other Query methods (fetch etc).class Foo extends Model {}
Foo.fields = { id: 'integer' };
class Bar extends Model {}
Bar.fields = { id: 'integer' };
class Quux extends Model {}
Foo.fields = {
refId: {
type: 'integer',
// multiple references can be defined as an array
// or as a function that returns an array
references: [Foo.fields.id, Bar.fields.id]
}
};
// these fetches would now supported:
Quux.fetch({ join: Foo });
Quux.fetch({ join: Bar });
Foo.fetch({ join: Quux });
Bar.fetch({ join: Quux });
first
on joined queries (165ddb9)orderBy
(89a3343)on
does not support multiple fields (80788d8)null
if the row is empty (3f0143b)references
as a function (b31b046)null
when no rows are matched (29b97e8)