Skip to content

Commit 4aaecee

Browse files
committed
Add skipFields
1 parent 62dac0c commit 4aaecee

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface ORMModel {
3232
name: string;
3333
entity: string;
3434
eagerLoad: undefined | Array<string>;
35+
skipFields: undefined | Array<string>;
3536

3637
fields (): any;
3738
dispatch (name: string, ...params: Array<any>): any;

src/model.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ export default class Model {
4242
}
4343

4444
/**
45-
* Tells if a field should be ignored. This is true for fields that start with a `$` and all foreign keys
45+
* Tells if a field should be ignored. This is true for fields that start with a `$` or is it is within the skipField
46+
* property.
47+
*
4648
* @param {string} field
4749
* @returns {boolean}
4850
*/
4951
public skipField (field: string) {
5052
if (field.startsWith('$')) return true;
53+
if (this.baseModel.skipFields && this.baseModel.skipFields.indexOf(field) >= 0) return true;
5154

5255
let shouldSkipField: boolean = false;
5356

test/integration/VuexORMApollo.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class User extends ORMModel {
2020
class Video extends ORMModel {
2121
static entity = 'videos';
2222
static eagerLoad = ['comments'];
23+
static skipFields = ['ignoreMe'];
2324

2425
static fields () {
2526
return {
@@ -28,6 +29,7 @@ class Video extends ORMModel {
2829
title: this.string(''),
2930
userId: this.number(0),
3031
otherId: this.number(0), // This is a field which ends with `Id` but doesn't belong to any relation
32+
ignoreMe: this.string(''),
3133
user: this.belongsTo(User, 'userId'),
3234
comments: this.morphMany(Comment, 'subjectId', 'subjectType')
3335
};

0 commit comments

Comments
 (0)