template_utils.js.html 5.93 KB
<!DOCTYPE html>

<html lang="en">
<head>
	<meta charset="utf-8">
	<title>sequelize-pg-generator Source: template/utils.js</title>

	<!--[if lt IE 9]>
	<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
	<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">

	<link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">

</head>

<body>
<div class="container-fluid">
	<div class="navbar navbar-fixed-top navbar-inverse">
		<div class="navbar-inner">
			<a class="brand" href="index.html">sequelize-pg-generator</a>
			<ul class="nav">
				
				<li class="dropdown">
					<a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b
						class="caret"></b></a>

					<ul class="dropdown-menu ">
						
						<li>
							<a href="module-lib_index.html">lib/index</a>
						</li>
						
						<li>
							<a href="module-path_to_model.html">path/to/model</a>
						</li>
						

					</ul>
				</li>
				
				<li class="dropdown">
					<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
						class="caret"></b></a>

					<ul class="dropdown-menu ">
						
						<li>
							<a href="GeneratorUtil.html">GeneratorUtil</a>
						</li>
						

					</ul>
				</li>
				
			</ul>
		</div>
	</div>

	<div class="row-fluid">

		
			<div class="span12">
				
				<div id="main">
					


		<h1 class="page-title">Source: template/utils.js</h1>
    
<section>
	<article>
		<pre
			class="sunlight-highlight-javascript linenums">/**
 * Utility methods to modify and customize auto generated models without affecting further auto generations.
 * Require this module from model customization scripts located in path/to/model/definitions-files-custom directory.
 * @class
 * @author Özüm Eldoğan
 */


/*jslint node: true */
"use strict";


/**
 * @constructor
 * @param model
 */
var GeneratorUtil = function (model) {
    this.model = model;
};


/**
 * Searches and returns relation with the given alias. Alias is defined in sequelize options with parameter 'as'
 * @method
 * @param {string} as - Alias of the relation.
 * @returns {Object}
 */
GeneratorUtil.prototype.getRelation = function (as) {
    var i,
        relations = this.model.relations;
    for (i = 0; i &lt; relations.length; i = i + 1) {
        if (relations[i].details.as === as) {
            return relations[i];
        }
    }
};


/**
 * Searches and returns attribute with the given alias. Alias is defined in sequelize options with parameter 'as'
 * @method
 * @param {string} name - Name of the attribute.
 * @returns {Object}
 */
GeneratorUtil.prototype.getAttribute = function (name) {
    return this.model.attributes[name];
};


/**
 * Searches and returns attribute with the given alias. Alias is defined in sequelize options with parameter 'as'
 * @method
 * @param {string} oldName - Name of the attribute which it's name to be changed.
 * @param {string} newName - New name of the attribute.
 * @throws Will throw error if there is already an attribute with new name exists or attribute with oldName does not exists.
 */
GeneratorUtil.prototype.renameAttribute = function (oldName, newName) {
    if (this.model.attributes[newName] !== undefined) {
        throw new Error('There is already an attribute with the same name ("' + newName + '") in table "' + this.model.modelName + '".');
    }
    if (this.model.attributes[oldName] === undefined) {
        throw new Error('There is no attribute with the name "' + oldName + '". in table "' + this.model.modelName + '".');
    }
    this.model.attributes[newName] = this.model.attributes[oldName];
    delete this.model.attributes[oldName];
};


/**
 * Creates and returns new object with utility functions.
 * @param model
 * @returns {GeneratorUtil}
 */
module.exports = function (model) {
    return new GeneratorUtil(model);
};

</pre>
	</article>
</section>





				</div>

				<div class="clearfix"></div>
				<footer>
					
					
		<span class="copyright">
		sequelize-pg-generator Copyright © 2014 Özüm Eldoğan.
		</span>
					<br />
					
		<span class="jsdoc-message">
		Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0-dev</a>
		on Fri Nov 27th 2015 using the <a
			href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
		</span>
				</footer>
			</div>

			
			<br clear="both">
		</div>

	</div>
	<!--<script src="scripts/sunlight.js"></script>-->
	<script src="scripts/docstrap.lib.js"></script>
	<script src="scripts/bootstrap-dropdown.js"></script>
	<script src="scripts/toc.js"></script>

	<script>
		$( function () {
			$( "[id*='$']" ).each( function () {
				var $this = $( this );

				$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
			} );

			$( "#toc" ).toc( {
				anchorName  : function ( i, heading, prefix ) {
					return $( heading ).attr( "id" ) || ( prefix + i );
				},
				selectors   : "h1,h2,h3,h4",
				showAndHide : false,
				scrollTo    : "100px"
			} );

			$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
			$( "#main span[id^='toc']" ).addClass( "toc-shim" );
			$( '.dropdown-toggle' ).dropdown();
//			$( ".tutorial-section pre, .readme-section pre" ).addClass( "sunlight-highlight-javascript" ).addClass( "linenums" );

			$( ".tutorial-section pre, .readme-section pre" ).each( function () {
				var $this = $( this );

				var example = $this.find( "code" );
				exampleText = example.html();
				var lang = /{@lang (.*?)}/.exec( exampleText );
				if ( lang && lang[1] ) {
					exampleText = exampleText.replace( lang[0], "" );
					example.html( exampleText );
					lang = lang[1];
				} else {
					lang = "javascript";
				}

				if ( lang ) {

					$this
						.addClass( "sunlight-highlight-" + lang )
						.addClass( "linenums" )
						.html( example.html() );

				}
			} );

			Sunlight.highlightAll( {
				lineNumbers : true,
				showMenu : true,
				enableDoclinks : true
			} );
		} );
	 </script>



	<!--Navigation and Symbol Display-->
	


	<!--Google Analytics-->
	

</body>
</html>