How to use the ember-data/relationships.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 hummingbird-me / hummingbird-client / app / models / user.js View on Github external
subscribedToNewsletter: attr('boolean'),
  timeZone: attr('string'),
  title: attr('string'),
  titleLanguagePreference: attr('string', { defaultValue: 'canonical' }),
  theme: attr('string', { defaultValue: 'light' }),
  waifuOrHusbando: attr('string'),
  updatedAt: attr('utc'),

  // NOTE: These properties are not used for mapping posts to user
  // without them, ember-data will override its null inverse!
  posts: hasMany('post', { inverse: 'user' }),
  receivedPosts: hasMany('post', { inverse: 'targetUser' }),
  uploads: hasMany('upload', { inverse: 'user' }),

  waifu: belongsTo('character'),
  pinnedPost: belongsTo('post', { inverse: null }),

  blocks: hasMany('block', { inverse: 'user' }),
  favorites: hasMany('favorite', { inverse: 'user' }),
  followers: hasMany('follow', { inverse: 'followed' }),
  following: hasMany('follow', { inverse: 'follower' }),
  notificationSettings: hasMany('notification-setting', { inverse: 'user' }),
  oneSignalPlayers: hasMany('one-signal-player', { inverse: 'user' }),
  profileLinks: hasMany('profile-link', { inverse: 'user' }),
  stats: hasMany('stat', { inverse: 'user' }),
  userRoles: hasMany('user-role'),

  // HACK: We use this to flag the model as dirty when waifu changes, as ember-data
  // doesn't currently track the dirtiness of a relationship.
  waifuDirtyHack: attr('boolean', { defaultValue: false }),

  url: or('slug', 'id'),
github streamlink / streamlink-twitch-gui / src / app / data / models / stream / model.js View on Github external
qualitiesStreamlink,
	qualitiesLivestreamer
};


@name( "Stream" )
export default class Stream extends Model {
	/** @type {AuthService} */
	@service auth;
	/** @type {SettingsService} */
	@service settings;
	/** @type {StreamingService} */
	@service streaming;

	/** @type {TwitchStream} */
	@belongsTo( "twitch-stream", { async: false } )
	stream;
	/** @type {TwitchChannel} */
	@belongsTo( "twitch-channel", { async: false } )
	channel;
	@attr( "string" )
	quality;
	@attr( "boolean" )
	chat_open;
	@attr( "date" )
	started;


	// let Streamlink/Livestreamer use the GUI's client-id
	clientID = `Client-ID=${clientId}`;

	// passthrough type (twitch streams are HLS)
github hummingbird-me / hummingbird-client / app / models / profile-link.js View on Github external
import Base from 'client/models/-base';
import attr from 'ember-data/attr';
import { belongsTo } from 'ember-data/relationships';
import { get, computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { regularExpressions } from 'ember-validators/format';

export default Base.extend({
  url: attr('string'),

  profileLinkSite: belongsTo('profile-link-site'),
  user: belongsTo('user', { inverse: 'profileLinks' }),

  site: alias('profileLinkSite'),
  isURL: computed('url', function() {
    const url = get(this, 'url');
    return regularExpressions.url.test(url);
  }).readOnly()
});
github streamlink / streamlink-twitch-gui / src / app / data / models / twitch / search-channel / model.js View on Github external
import Model from "ember-data/model";
import { belongsTo } from "ember-data/relationships";


export default Model.extend({
	channel: belongsTo( "twitchChannel", { async: false } )

}).reopenClass({
	toString() { return "kraken/search/channels"; }
});
github oliverbarnes / old-participate-client / app / models / delegation.js View on Github external
import Model from 'ember-data/model';
import { belongsTo } from 'ember-data/relationships';

export default Model.extend({
  proposal: belongsTo(),
  author: belongsTo('participant', {
    inverse: 'delegationsGiven'
  }),
  delegate: belongsTo('participant')
});
github hummingbird-me / hummingbird-client / app / models / group-action-log.js View on Github external
import Base from 'client/models/-base';
import attr from 'ember-data/attr';
import { belongsTo } from 'ember-data/relationships';

export default Base.extend({
  verb: attr('string'),

  group: belongsTo('group', { inverse: 'actionLogs' }),
  user: belongsTo('user'),
  target: belongsTo('-base')
});
github hummingbird-me / hummingbird-client / app / models / comment / model.js View on Github external
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';

export default Model.extend({
  blocked: attr('boolean'),
  content: attr('string'),
  contentFormatted: attr('string'),
  createdAt: attr('date', { defaultValue() { return new Date(); } }),
  deletedAt: attr('date'),
  likesCount: attr('number'),
  repliesCount: attr('number'),

  parent: belongsTo('comment', { inverse: 'replies' }),
  post: belongsTo('post', { inverse: 'comments' }),
  user: belongsTo('user'),

  likes: hasMany('comment-like', { inverse: 'comment' }),
  replies: hasMany('comment', { inverse: 'parent' })
});
github hummingbird-me / hummingbird-client / app / models / chapter.js View on Github external
import attr from 'ember-data/attr';
import { belongsTo } from 'ember-data/relationships';
import Base from 'client/models/-base';

export default Base.extend({
  published: attr('utc'),
  canonicalTitle: attr('string'),
  length: attr('number'),
  number: attr('number'),
  volumeNumber: attr('number'),
  synopsis: attr('string'),
  thumbnail: attr('object'),
  titles: attr('object'),

  manga: belongsTo('manga', { inverse: 'chapters' })
});
github streamlink / streamlink-twitch-gui / src / app / data / models / twitch / user / model.js View on Github external
import Model from "ember-data/model";
import { belongsTo } from "ember-data/relationships";


/**
 * This model is only being used for mapping channel names to user IDs.
 * Users are being looked up via GET /kraken/users?login=:name
 *
 * The primary key is the user/channel name, so it can be looked up via store.findRecord.
 * The original primary key (_id) is used as a key for TwitchChannel/TwitchStream relationships.
 */
export default Model.extend({
	channel: belongsTo( "twitchChannel", { async: true } ),
	stream: belongsTo( "twitchStream", { async: true } )

}).reopenClass({
	toString() { return "kraken/users"; }
});