How to use the redux-orm.fk function in redux-orm

To help you get started, we’ve selected a few redux-orm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SEL-Columbia / dokomoforms / dokomoforms / static / src / admin / js / create-survey / redux / models.babel.js View on Github external
class Bucket extends CRUDModel {
    denormalize() {
        const data = Object.assign({}, this.ref)
        delete data.id;
        delete data.survey;
        return data;
    }
};

Bucket.modelName = 'Bucket';

Bucket.fields = {
    id: attr(), // non-relational field for any value; optional but highly recommended
    bucket_type: attr(),
    bucket: attr(),
    survey: fk('Survey', 'buckets')
};


class Logic extends CRUDModel {
    denormalize() {
        const data = Object.assign({}, this.ref)
        delete data.id
        delete data.question
        return data
    }
};

Logic.modelName = 'Logic';

Logic.fields = {
    id: attr(),
github GiraffeTools / GiraffeTools / frontend / porcupine / models / link.js View on Github external
.forEach((link) => {
              // #TODO check if this is safe when REMOVE_NODE deletes nodeModel
              if (link.portFromModel.outputParent.id == payload.parameterId) {
                link.portToModel.inputParent.update(payload.newValues);
              }
            });

        break;
    }
    return undefined;
  }
}
Link.modelName = 'Link';
Link.fields = {
  id: attr(),
  portFrom: fk({
    to: 'Port',
    as: 'portFromModel',
    relatedName: 'outputLinks',
  }),
  portTo: fk({
    to: 'Port',
    as: 'portToModel',
    relatedName: 'inputLinks',
  }),
};

export default Link;
github SEL-Columbia / dokomoforms / dokomoforms / static / src / admin / js / create-survey / redux / models.babel.js View on Github external
Logic.modelName = 'Logic';

Logic.fields = {
    id: attr(),
    question: oneToOne('Question')
};


class Choice extends CRUDModel {};

Choice.modelName = 'Choice';

Choice.fields = {
    id: attr(),
    question: fk('Question', 'multiple_choices')
}


const orm = new ORM();
orm.register(Survey, Node, Question, Bucket, Logic, Choice);

console.log('new orm', orm)

export {Survey, Node, Question, Bucket, Logic, Choice, orm}
github markerikson / project-minimek / src / features / unitInfo / Unit.js View on Github external
import {Model, many, fk, attr} from "redux-orm";


export default class Unit extends Model {
    static modelName = "Unit";

    static fields = {
        id : attr(),
        name : attr(),
        affiliation : fk("Faction"),
        color : attr(),
        lances : many("Lance"),
        pilots : many("Pilot"),
        mechs : many("Mech")
    };

    static parse(unitData) {
        const {Pilot, Mech, Lance} = this.session;

        const parsedData = {
            ...unitData,
            lances : unitData.lances.map(lanceEntry => Lance.parse(lanceEntry)),
            pilots : unitData.pilots.map(pilotEntry => Pilot.parse(pilotEntry)),
            mechs : unitData.mechs.map(mechEntry => Mech.parse(mechEntry)),
        };
github wq / wq.app / packages / model / src / model.js View on Github external
(config.form || []).forEach(field => {
                        if (field['wq:ForeignKey']) {
                            fields[field.name + '_id'] = fk({
                                to: field['wq:ForeignKey'],
                                as: field.name,
                                relatedName:
                                    field['wq:related_name'] ||
                                    config.url ||
                                    config.name + 's'
                            });
                        } else if (field.type !== 'repeat') {
                            fields[field.name] = attr();
                        }
                    });
                    return fields;
github piximi / application / src / models / image.js View on Github external
import { attr, fk, Model } from 'redux-orm';

class Image extends Model {}

Image.modelName = 'image';

Image.fields = {
  category: fk('category', 'images'),
  checksum: attr(),
  data: attr(),
  id: attr()
};

export default Image;
github GiraffeTools / GiraffeTools / app / porcupine / js / models / link.js View on Github external
}
          });
        break;
    }
    return undefined;
  }
}
Link.modelName = "Link";
Link.fields = {
  id: attr(),
  portFrom: fk({
    to: "Port",
    as: "portFromModel",
    relatedName: "outputLinks"
  }),
  portTo: fk({
    to: "Port",
    as: "portToModel",
    relatedName: "inputLinks"
  })
};

export default Link;
github meltyshev / planka / client / src / models / Card.js View on Github external
timer: attr(),
    isSubscribed: attr({
      getDefault: () => false,
    }),
    isActionsFetching: attr({
      getDefault: () => false,
    }),
    isAllActionsFetched: attr({
      getDefault: () => false,
    }),
    listId: fk({
      to: 'List',
      as: 'list',
      relatedName: 'cards',
    }),
    boardId: fk({
      to: 'Board',
      as: 'board',
      relatedName: 'cards',
    }),
    users: many('User', 'cards'),
    labels: many('Label', 'cards'),
  };

  static reducer({ type, payload }, Card) {
    switch (type) {
      case ActionTypes.USER_TO_CARD_ADD: {
        const cardModel = Card.withId(payload.cardId);
        cardModel.users.add(payload.id);

        if (payload.isCurrent) {
          cardModel.isSubscribed = true;
github markerikson / project-minimek-educative / src / features / mechs / Mech.js View on Github external
import {Model, fk, attr} from "redux-orm";

export default class Mech extends Model {
    static modelName = "Mech";

    static fields = {
        id : attr(),
        type : fk("MechDesign"),
        pilot : fk("Pilot"),
    };

    static parse(mechData) {
        return this.create(mechData);
    }
}
github ksco / reblog / src / models / Comment.js View on Github external
static get fields() {
    return {
      id: attr(),
      body: attr(),
      createdAt: attr(),
      updatedAt: attr(),
      user: fk('User', 'comments'),
      post: fk('Post', 'comments'),
    }
  }

redux-orm

Simple ORM to manage and query your state trees

MIT
Latest version published 4 years ago

Package Health Score

51 / 100
Full package analysis