Skip to content

Commit

Permalink
add YUI docs for belongsTo (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
Azdaroth authored and samselikoff committed Sep 3, 2016
1 parent d312e51 commit b3bebc3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions addon/orm/associations/belongs-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,47 @@ import { capitalize, camelize } from 'ember-cli-mirage/utils/inflector';
import { toCollectionName } from 'ember-cli-mirage/utils/normalize-name';
import assert from 'ember-cli-mirage/assert';

/**
* @class BelongsTo
* @extends Association
* @constructor
* @public
*/
class BelongsTo extends Association {

/*
The belongsTo association adds a fk to the owner of the association
*/
/**
* @method getForeignKeyArray
* @return {Array} Array of camelized name of the model owning the association
* and foreign key for the association
* @public
*/
getForeignKeyArray() {
return [camelize(this.ownerModelName), this.getForeignKey()];
}

/**
* @method getForeignKey
* @return {String} Foreign key for the association
* @public
*/
getForeignKey() {
return `${camelize(this.key)}Id`;
}

/**
* registers belongs-to association defined by given key on given model,
* defines getters / setters for associated parent and associated parent's id,
* adds methods for creating unsaved parent record and creating a saved one
*
* @method addMethodsToModelClass
* @param {Function} ModelClass
* @param {String} key
* @param {Schema} schema
* @public
*/
addMethodsToModelClass(ModelClass, key, schema) {
let modelPrototype = ModelClass.prototype;
let association = this;
Expand Down

0 comments on commit b3bebc3

Please sign in to comment.