UNPKG

@herlinus/coloquent

Version:

Library for retrieving model objects from a JSON-API, with a fluent syntax inspired by Laravel Eloquent.

36 lines 1.71 kB
import { Relation } from "./Relation"; import { Builder } from "../Builder"; export class ToManyRelation extends Relation { get(page) { return new Builder(this.getType(), this.getName(), this.getReferringObject().getJsonApiType(), this.getReferringObject().getApiId()) .get(page); } first() { return new Builder(this.getType(), this.getName(), this.getReferringObject().getJsonApiType(), this.getReferringObject().getApiId()) .first(); } find(id) { return new Builder(this.getType(), this.getName(), this.getReferringObject().getJsonApiType(), this.getReferringObject().getApiId()) .find(id); } where(attribute, value) { return new Builder(this.getType(), this.getName(), this.getReferringObject().getJsonApiType(), this.getReferringObject().getApiId()) .where(attribute, value); } with(value) { return new Builder(this.getType(), this.getName(), this.getReferringObject().getJsonApiType(), this.getReferringObject().getApiId()) .with(value); } orderBy(attribute, direction) { return new Builder(this.getType(), this.getName(), this.getReferringObject().getJsonApiType(), this.getReferringObject().getApiId()) .orderBy(attribute, direction); } option(queryParameter, value) { return new Builder(this.getType(), this.getName(), this.getReferringObject().getJsonApiType(), this.getReferringObject().getApiId()) .option(queryParameter, value); } get data() { return this.getReferringObject().getRelation(this.name); } } //# sourceMappingURL=ToManyRelation.js.map