How to use the @ember-data/model.belongsTo 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 / consul / ui / packages / consul-ui / app / models / service-instance.js View on Github external
get ExternalSources() {
    const sources = this.items.reduce(function(prev, item) {
      return prev.concat(item.ExternalSources || []);
    }, []);
    // unique, non-empty values, alpha sort
    return [...new Set(sources)].filter(Boolean).sort();
  }
};

export default class ServiceInstance extends Model {
  @attr('string') uid;

  @attr('string') Datacenter;
  // ProxyInstance is the ember-data model relationship
  @belongsTo('Proxy') ProxyInstance;
  // Proxy is the actual JSON api response
  @attr() Proxy;
  @attr() Node;
  @attr() Service;
  @fragmentArray('health-check') Checks;
  @attr('number') SyncTime;
  @attr() meta;
  @attr({ defaultValue: () => [] }) Resources; // []

  // The name is the Name of the Service (the grouping of instances)
  @alias('Service.Service') Name;

  // If the ID is blank fallback to the Service.Service (the Name)
  @or('Service.{ID,Service}') ID;
  @or('Service.Address', 'Node.Service') Address;
  @attr('string') SocketPath;
github hashicorp / nomad / ui / app / models / allocation.js View on Github external
@equal('clientStatus', 'running') isRunning;
  @attr('boolean') isMigrating;

  @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',
github travis-ci / travis-web / app / models / request.js View on Github external
event_type: attr(),
  result: attr(),
  message: attr('string'),
  headCommit: attr(),
  baseCommit: attr(),
  branchName: attr('string'),
  pullRequestMergeable: attr('string'),
  tagName: attr('string'),
  pullRequest: attr('boolean'),
  pullRequestTitle: attr('string'),
  pullRequestNumber: attr('number'),
  config: attr(),
  raw_configs: attr(),
  uniqRawConfigs: uniqBy('raw_configs', 'source'),
  noYaml: empty('raw_configs'),
  repo: belongsTo('repo', { async: true }),
  commit: belongsTo('commit', { async: true }),

  // API models this as hasMany but serializers:request#normalize overrides it
  build: belongsTo('build', { async: true }),

  isAccepted: computed('result', 'build.id', function () {
    // For some reason some of the requests have a null result beside the fact that
    // the build was created. We need to look into it, but for now we can just assume
    // that if build was created, the request was accepted

    let result = this.result;
    let buildId = this.get('build.id');

    return result === 'approved' || buildId;
  }),
github travis-ci / travis-web / app / models / job.js View on Github external
features: service(),
  logId: attr(),
  queue: attr(),
  state: attr(),
  number: attr(),
  allowFailure: attr('boolean'),
  tags: attr(),
  repositoryPrivate: attr(),
  repositorySlug: attr(),
  updatedAt: attr('date'),
  _config: attr(),

  repo: belongsTo('repo'),
  build: belongsTo('build', { async: true }),
  commit: belongsTo('commit', { async: true }),
  stage: belongsTo('stage', { async: true }),

  isPullRequest: alias('build.isPullRequest'),
  pullRequestNumber: alias('build.pullRequestNumber'),
  pullRequestTitle: alias('build.pullRequestTitle'),
  branch: alias('build.branch'),
  branchName: alias('build.branchName'),
  isTag: alias('build.isTag'),
  tag: alias('build.tag'),
  eventType: alias('build.eventType'),

  // TODO: DO NOT SET OTHER PROPERTIES WITHIN A COMPUTED PROPERTY!
  log: computed(function () {
    this.set('isLogAccessed', true);
    return Log.create({
      job: this,
      api: this.api,
github hashicorp / nomad / ui / app / models / volume.js View on Github external
import { computed } from '@ember/object';
import Model from '@ember-data/model';
import { attr, belongsTo, hasMany } from '@ember-data/model';

export default class Volume extends Model {
  @attr('string') plainId;
  @attr('string') name;

  @belongsTo('namespace') namespace;
  @belongsTo('plugin') plugin;

  @hasMany('allocation') writeAllocations;
  @hasMany('allocation') readAllocations;

  @computed('writeAllocations.[]', 'readAllocations.[]')
  get allocations() {
    return [...this.writeAllocations.toArray(), ...this.readAllocations.toArray()];
  }

  @attr('number') currentWriters;
  @attr('number') currentReaders;

  @computed('currentWriters', 'currentReaders')
  get allocationCount() {
    return this.currentWriters + this.currentReaders;
  }
github travis-ci / travis-web / app / models / invoices.js View on Github external
import Model, { attr, belongsTo } from '@ember-data/model';

export default Model.extend({
  createdAt: attr('date'),
  url: attr('string'),

  subscription: belongsTo('subscription')
});
github emberobserver / client / app / models / addon-size.js View on Github external
@attr('number')
  appCssSize;

  @attr('number')
  vendorJsSize;

  @attr('number')
  vendorCssSize;

  @attr('number')
  otherJsSize;

  @attr('number')
  otherCssSize;

  @belongsTo('version')
  addonVersion;

  @computed('appJsSize', 'vendorJsSize', 'otherJsSize')
  get totalJsSize() {
    return this.appJsSize + this.vendorJsSize + this.otherJsSize;
  }

  @computed('appCssSize', 'vendorCssSize', 'otherJCssSize')
  get totalCssSize() {
    return this.appCssSize + this.vendorCssSize + this.otherCssSize;
  }
}
github NREL / api-umbrella / src / api-umbrella / admin-ui / app / models / api.js View on Github external
export default Model.extend(Validations, {
  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 hashicorp / vault / ui / app / models / identity / entity-alias.js View on Github external
import { belongsTo, attr } from '@ember-data/model';
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import IdentityModel from './_base';
import identityCapabilities from 'vault/macros/identity-capabilities';

export default IdentityModel.extend({
  parentType: 'entity',
  formFields: computed(function() {
    return ['name', 'mountAccessor'];
  }),
  entity: belongsTo('identity/entity', { readOnly: true, async: false }),

  name: attr('string'),
  canonicalId: attr('string'),
  mountAccessor: attr('string', {
    label: 'Auth Backend',
    editType: 'mountAccessor',
  }),
  metadata: attr({
    editType: 'kv',
  }),
  mountPath: attr('string', {
    readOnly: true,
  }),
  mountType: attr('string', {
    readOnly: true,
  }),
github emberobserver / client / app / models / addon-dependency.js View on Github external
import classic from 'ember-classic-decorator';
import { equal } from '@ember/object/computed';
import Model, { belongsTo, attr } from '@ember-data/model';

@classic
export default class AddonDependency extends Model {
  @attr('string')
  package;

  @attr('string')
  dependencyType;

  @belongsTo('version')
  dependentVersion;

  @equal('dependencyType', 'dependencies')
  isDependency;

  @equal('dependencyType', 'devDependencies')
  isDevDependency;
}

@ember-data/model

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

MIT
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis