UNPKG

@statezero/core

Version:

The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate

72 lines (71 loc) 2.67 kB
/** * This file was auto-generated. Do not make direct changes to the file. */ import { Model, Manager, QuerySet, getModelClass } from '../../../../src'; import { wrapReactiveModel } from '../../../../src'; import schemaData from './modelwithcustompkrelation.schema.json'; /** * Model-specific QuerySet implementation */ export class ModelWithCustomPKRelationQuerySet extends QuerySet { } /** * Model-specific Manager implementation */ export class ModelWithCustomPKRelationManager extends Manager { constructor(ModelClass) { super(ModelClass, ModelWithCustomPKRelationQuerySet); } newQuerySet() { return new ModelWithCustomPKRelationQuerySet(this.ModelClass); } } /** * Implementation of the ModelWithCustomPKRelation model */ export class ModelWithCustomPKRelation extends Model { constructor(data) { ModelWithCustomPKRelation.validateFields(data); super(data); // Define getters and setters for all fields this._defineProperties(); return wrapReactiveModel(this); } /** * Define property getters and setters for all model fields * @private */ _defineProperties() { // For each field, define a property that gets/sets from internal storage ModelWithCustomPKRelation.fields.forEach(field => { Object.defineProperty(this, field, { get: function () { return this.getField(field); }, set: function (value) { this.setField(field, value); }, enumerable: true, // Make sure fields are enumerable for serialization configurable: true }); }); // Add a special read-only getter for the repr field Object.defineProperty(this, 'repr', { get: function () { return this.getField('repr'); }, enumerable: true, // Make sure repr is enumerable configurable: true }); } } // Bind this model to its backend ModelWithCustomPKRelation.configKey = 'default'; ModelWithCustomPKRelation.modelName = 'django_app.modelwithcustompkrelation'; ModelWithCustomPKRelation.primaryKeyField = 'id'; ModelWithCustomPKRelation.objects = new ModelWithCustomPKRelationManager(ModelWithCustomPKRelation); ModelWithCustomPKRelation.fields = ['id', 'name', 'custom_pk_related']; ModelWithCustomPKRelation.schema = schemaData; ModelWithCustomPKRelation.relationshipFields = new Map([ ['custom_pk_related', { 'ModelClass': () => getModelClass('django_app.custompkmodel', 'default'), 'relationshipType': 'foreign-key' }] ]);