Skip to content

Relations

mbroersen edited this page Oct 15, 2020 · 1 revision

Main usage

Should be added to the class field list. The relations add helper getter and setters on the parent class of the relation

Supported Relations

  • BelongsTo
  • HasMany
  • HasManyThrough
  • HasOne
  • MorphOne
Class User extends Model {
  constructor() {
    const fields = [
      new BelongsTo(Team)
    ];

    super(fields);
  }
}

BelongsTo

import

import {BelongsTo} from 'jeloquent';

creation

new BelongsTo(team);

HasMany

import

import {HasMany} from 'jeloquent';

creation

new HasMany(User);

HasManyThrough

import

import {HasManyThrough} from 'jeloquent';

creation

new HasMany(Comment, User);

HasOne

import

import {HasOne} from 'jeloquent';

creation

new HasOne(User);

MorphOne

import

import {MorphOne} from 'jeloquent';

creation

new MorphOne(Avatar)

Clone this wiki locally