How to use the ember-data.belongsTo function in ember-data

To help you get started, we’ve selected a few ember-data 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 HospitalRun / hospitalrun-frontend / app / models / appointment.js View on Github external
import moment from 'moment';
import PatientValidation from 'hospitalrun/utils/patient-validation';

export default AbstractModel.extend({
  // Attributes
  allDay: DS.attr(),
  provider: DS.attr('string'),
  location: DS.attr('string'),
  appointmentType: DS.attr('string'),
  startDate: DS.attr('date'),
  endDate: DS.attr('date'),
  notes: DS.attr('string'),
  status: DS.attr('string', { defaultValue: 'Scheduled' }),

  // Associations
  patient: DS.belongsTo('patient', { async: false }),
  visits: DS.hasMany('visit'),

  // Formats
  longDateFormat: 'l h:mm A',
  shortDateFormat: 'l',
  timeFormat: 'h:mm A',

  _getDateSpan(startDate, endDate, format) {
    let formattedStart = startDate.format(format);
    let formattedEnd = endDate.format(format);
    return `${formattedStart} - ${formattedEnd}`;
  },

  appointmentDate: computed('startDate', function() {
    let startDate = this.get('startDate');
    return startDate;
github mgenev / how-to-sane / client / app / models / event.js View on Github external
import DS from 'ember-data';

export default DS.Model.extend({
    // relationships
    vendor: DS.belongsTo('vendor'),
    users: DS.hasMany('user'),

    // attributes
    title: DS.attr('string'),
    date: DS.attr('date'),
    tags: DS.attr('array')
});
github scrapinghub / portia / portiaui / app / models / item-annotation.js View on Github external
import Ember from 'ember';
import DS from 'ember-data';
import Annotation from './annotation';

export default Annotation.extend({
    name: DS.attr('string'),
    item: DS.belongsTo({
        async: true,
        inverse: 'itemAnnotation'
    }),
    repeatedAcceptSelectors: DS.attr('array'), // Selector of repeated container inside container
    siblings: DS.attr('number'),     // Number of siblings to look at for repeated container
    field: DS.attr('string'),   // Field to extract to in parent container

    acceptSelectors: DS.attr('array'),
    rejectSelectors: DS.attr('array'),

    orderedAnnotations: Ember.computed.readOnly('item.orderedAnnotations'),
    orderedChildren: Ember.computed.readOnly('item.orderedChildren'),

    save() {
        return this._super(...arguments).then(result => {
            const annotations = this.get('item.annotations');
github coding-blocks / codingblocks.online.projectx / app / models / progress.js View on Github external
import DS from 'ember-data';
import { computed } from '@ember/object'

export default DS.Model.extend({
  status: DS.attr(),
  feedbackStatus: DS.attr(),
  isDone: computed('status', function () {
    return this.status === 'DONE';
  }),
  isActive: computed('status', function(){
    return this.status === 'ACTIVE';
  }),
  isFeedbackDone: computed('feedbackStatus', function() {
    return !(this.feedbackStatus == null);
  }),
  runAttempt: DS.belongsTo('runAttempt'),
  content: DS.belongsTo('content'),
})
github Flexberry / ember-flexberry-designer / addon / mixins / regenerated / models / fd-dev-associated-detail-view.js View on Github external
import Ember from 'ember';
import DS from 'ember-data';
import { Projection } from 'ember-flexberry-data';
export let Model = Ember.Mixin.create({
  detailLoadOnLoadAgregator: DS.attr('boolean'),
  detailName: DS.attr('string'),
  detailViewName: DS.attr('string'),
  view: DS.belongsTo('fd-view', { inverse: null, async: false }),
  getValidations: function () {
    let parentValidations = this._super();
    let thisValidations = {
      view: { presence: true }
    };
    return Ember.$.extend(true, {}, parentValidations, thisValidations);
  },
  init: function () {
    this.set('validations', this.getValidations());
    this._super.apply(this, arguments);
  }
});
export let defineProjections = function (modelClass) {
  modelClass.defineProjection('Edit', 'fd-dev-associated-detail-view', {
    detailLoadOnLoadAgregator: Projection.attr(''),
    detailName: Projection.attr(''),
github aptible / dashboard.aptible.com / app / models / service.js View on Github external
import Ember from 'ember';
import DS from 'ember-data';

export default DS.Model.extend({
  vhosts: DS.hasMany('vhost', {async:true}),
  stack: DS.belongsTo('stack', {async:true}),
  app: DS.belongsTo('app', {async:true}),
  database: DS.belongsTo('database', {async:true}),

  handle: DS.attr('string'),
  command: DS.attr('string'),
  containerCount: DS.attr('number'),
  containerMemoryLimitMb: DS.attr('number'),
  processType: DS.attr('string'),

  currentRelease: DS.belongsTo('release', {async:true}),
  inService: Ember.computed.gt('containerCount', 0),
  containerSize: Ember.computed('containerMemoryLimitMb', function() {
    return this.get('containerMemoryLimitMb') || 1024;
  }),

  containerSizeGB: Ember.computed('containerMemoryLimitMb', function() {
github Flexberry / ember-flexberry-designer / addon / mixins / regenerated / models / fd-dev-form-control.js View on Github external
import Ember from 'ember';
import DS from 'ember-data';
import { Projection } from 'ember-flexberry-data';
export let Model = Ember.Mixin.create({
  name: DS.attr('string'),
  order: DS.attr('number'),
  propertyPath: DS.attr('string'),
  settingsXml: DS.attr('string'),
  controlType: DS.belongsTo('fd-dev-control-type', { inverse: null, async: false }),
  propertyType: DS.belongsTo('fd-dev-type-definition', { inverse: null, async: false }),
  formView: DS.belongsTo('fd-dev-form-view', { inverse: 'controls', async: false }),
  getValidations: function () {
    let parentValidations = this._super();
    let thisValidations = {
      name: { presence: true },
      controlType: { presence: true },
      propertyType: { presence: true },
      formView: { presence: true }
    };
    return Ember.$.extend(true, {}, parentValidations, thisValidations);
  },
  init: function () {
    this.set('validations', this.getValidations());
    this._super.apply(this, arguments);
  }
github ilios / frontend / app / models / curriculum-inventory-academic-level.js View on Github external
import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  description: DS.attr('string'),
  level: DS.attr('number'),
  report: DS.belongsTo('curriculum-inventory-report', {async: true}),
  sequenceBlocks: DS.hasMany('curriculum-inventory-sequence-block', {async: true}),
});
github coding-blocks / codingblocks.online.projectx / app / models / announcement.js View on Github external
import DS from 'ember-data';
import _moment from 'ember-moment/computeds/moment';
import fromNow from 'ember-moment/computeds/from-now';

export default DS.Model.extend ({
  title: DS.attr ("string"),
  text: DS.attr ("string"),
  createdAt: DS.attr (),
  updatedAt: DS.attr (),
  run: DS.belongsTo ('run'),
  user: DS.belongsTo ('user'),
  elapsedTime: fromNow (
    _moment ('createdAt'),
    false
  ),
});