How to use the @ember-data/model.hasMany function in @ember-data/model

To help you get started, we’ve selected a few @ember-data/model 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 hashicorp / nomad / ui / app / models / allocation.js View on Github external
@computed('clientStatus')
  get isScheduled() {
    return ['pending', 'running'].includes(this.clientStatus);
  }

  // An allocation model created from any allocation list response will be lacking
  // many properties (some of which can always be null). This is an indicator that
  // the allocation needs to be reloaded to get the complete allocation state.
  @none('allocationTaskGroup') isPartial;

  // When allocations are server-side rescheduled, a paper trail
  // is left linking all reschedule attempts.
  @belongsTo('allocation', { inverse: 'nextAllocation' }) previousAllocation;
  @belongsTo('allocation', { inverse: 'previousAllocation' }) nextAllocation;

  @hasMany('allocation', { inverse: 'preemptedByAllocation' }) preemptedAllocations;
  @belongsTo('allocation', { inverse: 'preemptedAllocations' }) preemptedByAllocation;
  @attr('boolean') wasPreempted;

  @belongsTo('evaluation') followUpEvaluation;

  @computed('clientStatus')
  get statusClass() {
    const classMap = {
      pending: 'is-pending',
      running: 'is-primary',
      complete: 'is-complete',
      failed: 'is-error',
      lost: 'is-light',
    };

    return classMap[this.clientStatus] || 'is-dark';
github jelhan / croodle / app / models / poll.js View on Github external
import Model, { hasMany, attr } from '@ember-data/model';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
import { computed } from '@ember/object';
import { equal } from '@ember/object/computed';

export default Model.extend({
  /*
   * relationships
   */
  users: hasMany('user', { async: false }),

  /*
   * properties
   */
  // Is participation without user name possibile?
  anonymousUser: attr('boolean'),

  // array of possible answers
  answers: fragmentArray('answer'),

  // YesNo, YesNoMaybe or Freetext
  answerType: attr('string'),

  // ISO-8601 combined date and time string in UTC
  creationDate: attr('date'),
github hashicorp / nomad / ui / app / models / job.js View on Github external
// True when the job is the parent periodic or parameterized jobs
  // Instances of periodic or parameterized jobs are false for both properties
  @attr('boolean') periodic;
  @attr('boolean') parameterized;
  @attr('boolean') dispatched;

  @attr() periodicDetails;
  @attr() parameterizedDetails;

  @computed('periodic', 'parameterized', 'dispatched')
  get hasChildren() {
    return this.periodic || (this.parameterized && !this.dispatched);
  }

  @belongsTo('job', { inverse: 'children' }) parent;
  @hasMany('job', { inverse: 'parent' }) children;

  // The parent job name is prepended to child launch job names
  @computed('name', 'parent.content')
  get trimmedName() {
    return this.get('parent.content') ? this.name.replace(/.+?\//, '') : this.name;
  }

  // A composite of type and other job attributes to determine
  // a better type descriptor for human interpretation rather
  // than for scheduling.
  @computed('type', 'periodic', 'parameterized')
  get displayType() {
    if (this.periodic) {
      return 'periodic';
    } else if (this.parameterized) {
      return 'parameterized';
github hashicorp / nomad / ui / app / models / job.js View on Github external
@alias('summary.totalAllocs') totalAllocs;
  @alias('summary.pendingChildren') pendingChildren;
  @alias('summary.runningChildren') runningChildren;
  @alias('summary.deadChildren') deadChildren;
  @alias('summary.totalChildren') totalChildren;

  @attr('number') version;

  @hasMany('job-versions') versions;
  @hasMany('allocations') allocations;
  @hasMany('deployments') deployments;
  @hasMany('evaluations') evaluations;
  @belongsTo('namespace') namespace;
  @belongsTo('job-scale') scaleState;

  @hasMany('recommendation-summary') recommendationSummaries;

  @computed('taskGroups.@each.drivers')
  get drivers() {
    return this.taskGroups
      .mapBy('drivers')
      .reduce((all, drivers) => {
        all.push(...drivers);
        return all;
      }, [])
      .uniq();
  }

  @mapBy('allocations', 'unhealthyDrivers') allocationsUnhealthyDrivers;

  // Getting all unhealthy drivers for a job can be incredibly expensive if the job
  // has many allocations. This can lead to making an API request for many nodes.
github emberobserver / client / app / models / test-result.js View on Github external
@attr('boolean')
  canary;

  @attr('string')
  output;

  @attr('string')
  outputFormat;

  @attr('string')
  semverString;

  @belongsTo('version')
  version;

  @hasMany('emberVersionCompatibility')
  emberVersionCompatibilities;

  @readOnly('createdAt')
  testsRunAt;
}
github hashicorp / nomad / ui / app / models / job.js View on Github external
@alias('summary.startingAllocs') startingAllocs;
  @alias('summary.runningAllocs') runningAllocs;
  @alias('summary.completeAllocs') completeAllocs;
  @alias('summary.failedAllocs') failedAllocs;
  @alias('summary.lostAllocs') lostAllocs;
  @alias('summary.totalAllocs') totalAllocs;
  @alias('summary.pendingChildren') pendingChildren;
  @alias('summary.runningChildren') runningChildren;
  @alias('summary.deadChildren') deadChildren;
  @alias('summary.totalChildren') totalChildren;

  @attr('number') version;

  @hasMany('job-versions') versions;
  @hasMany('allocations') allocations;
  @hasMany('deployments') deployments;
  @hasMany('evaluations') evaluations;
  @belongsTo('namespace') namespace;
  @belongsTo('job-scale') scaleState;

  @hasMany('recommendation-summary') recommendationSummaries;

  @computed('taskGroups.@each.drivers')
  get drivers() {
    return this.taskGroups
      .mapBy('drivers')
      .reduce((all, drivers) => {
        all.push(...drivers);
        return all;
      }, [])
      .uniq();
  }
github hashicorp / nomad / ui / app / models / job-plan.js View on Github external
import Model from '@ember-data/model';
import { attr } from '@ember-data/model';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
import { hasMany } from '@ember-data/model';

export default class JobPlan extends Model {
  @attr() diff;
  @fragmentArray('placement-failure', { defaultValue: () => [] }) failedTGAllocs;
  @hasMany('allocation') preemptions;
}
github NREL / api-umbrella / src / api-umbrella / admin-ui / app / models / api.js View on Github external
name: attr(),
  sortOrder: attr('number'),
  backendProtocol: attr('string', { defaultValue: 'http' }),
  frontendHost: attr(),
  backendHost: attr(),
  balanceAlgorithm: attr('string', { defaultValue: 'least_conn' }),
  createdAt: attr(),
  updatedAt: attr(),
  creator: attr(),
  updater: attr(),

  servers: hasMany('api/server', { async: false }),
  urlMatches: hasMany('api/url-match', { async: false }),
  settings: belongsTo('api/settings', { async: false }),
  subSettings: hasMany('api/sub-settings', { async: false }),
  rewrites: hasMany('api/rewrites', { async: false }),

  ready() {
    this.setDefaults();
    this._super();
  },

  setDefaults() {
    if(!this.settings) {
      this.set('settings', this.store.createRecord('api/settings'));
    }
  },

  exampleIncomingUrlRoot: computed('frontendHost', function() {
    return 'https://' + (this.frontendHost || '');
  }),
github emberobserver / client / app / models / addon.js View on Github external
@belongsTo('version', { async: true })
  latestAddonVersion;

  @belongsTo('review', { async: true })
  latestReview;

  @hasMany('category', { async: true })
  categories;

  @hasMany('keyword', { async: true })
  keywords;

  @hasMany('version', { async: true })
  versions;

  @hasMany('maintainer', { async: true })
  maintainers;

  @belongsTo('readme', { async: true })
  readme;

  @gt('githubUsers.length', 1)
  hasMoreThan1Contributor;

  @computed('name')
  get npmUrl() {
    return `https://www.npmjs.com/package/${this.name}`;
  }

  @computed('publishedDate')
  get isNewAddon() {
    return moment(this.publishedDate).isAfter(moment().subtract(2, 'weeks'));
github hashicorp / nomad / ui / app / models / job.js View on Github external
@alias('summary.queuedAllocs') queuedAllocs;
  @alias('summary.startingAllocs') startingAllocs;
  @alias('summary.runningAllocs') runningAllocs;
  @alias('summary.completeAllocs') completeAllocs;
  @alias('summary.failedAllocs') failedAllocs;
  @alias('summary.lostAllocs') lostAllocs;
  @alias('summary.totalAllocs') totalAllocs;
  @alias('summary.pendingChildren') pendingChildren;
  @alias('summary.runningChildren') runningChildren;
  @alias('summary.deadChildren') deadChildren;
  @alias('summary.totalChildren') totalChildren;

  @attr('number') version;

  @hasMany('job-versions') versions;
  @hasMany('allocations') allocations;
  @hasMany('deployments') deployments;
  @hasMany('evaluations') evaluations;
  @belongsTo('namespace') namespace;
  @belongsTo('job-scale') scaleState;

  @hasMany('recommendation-summary') recommendationSummaries;

  @computed('taskGroups.@each.drivers')
  get drivers() {
    return this.taskGroups
      .mapBy('drivers')
      .reduce((all, drivers) => {
        all.push(...drivers);
        return all;
      }, [])
      .uniq();

@ember-data/model

A basic Ember implementation of a resource presentation layer for use with @ember-data/store

MIT
Latest version published 1 month ago

Package Health Score

88 / 100
Full package analysis