<commit_before># sequelize-virtual-fields.js

# Sequelize virtual fields magic

## What's it for?

This plugin for [Sequelize](http://sequelizejs.com/) adds some magic to VIRTUAL fields, so that they can be used the same as normal fields.

If a virtual field references attributes of an associated model, this can be defined in the model's definition and the required associations are loaded automatically by `Model#find()`.

Why is this useful? You might, for example, want to build a Drupal-style framework where every model instance has a 'name' field which which may take its value from fields in associated models.

## Current status

[![Build Status](https://secure.travis-ci.org/overlookmotel/sequelize-virtual-fields.png)](http://travis-ci.org/overlookmotel/sequelize-virtual-fields)
[![Dependency Status](https://david-dm.org/overlookmotel/sequelize-virtual-fields.png)](https://david-dm.org/overlookmotel/sequelize-virtual-fields)

API is stable. Tested and works on MySQL. Untested on other dialects supported by Sequelize.

Requires recent master of Sequelize v2.x dev branch, more recent than 28 Oct 2014. This is more recent than v2.0.0-rc2 which is latest available on NPM. i.e. you need to get latest Sequelize from Github.

## Usage

### Loading module

To load module:

	var Sequelize = require('sequelize-virtual-fields')();
	// NB Sequelize must also be present in `node_modules`

or, a more verbose form useful if chaining multiple Sequelize plugins:

	var Sequelize = require('sequelize');
	require('sequelize-virtual-fields')(Sequelize);

### Defining virtual fields

Define the dependency of the virtual fields on other attributes or models:

	// define models
	var Person = sequelize.define('Person', { name: Sequelize.STRING });
	var Task = sequelize.define('Task', {
		name: Sequelize.STRING,
		nameWithPerson: {<commit_msg>README update<commit_after># sequelize-virtual-fields.js

# Sequelize virtual fields magic

## What's it for?

This plugin for [Sequelize](http://sequelizejs.com/) adds some magic to VIRTUAL fields, so that they can be used the same as normal fields.

If a virtual field references attributes of an associated model, this can be defined in the model's definition and the required associations are loaded automatically by `Model#find()`.

Why is this useful? You might, for example, want to build a Drupal-style framework where every model instance has a 'name' field which which may take its value from fields in associated models.

## Current status

[![Build Status](https://secure.travis-ci.org/overlookmotel/sequelize-virtual-fields.png)](http://travis-ci.org/overlookmotel/sequelize-virtual-fields)
[![Dependency Status](https://david-dm.org/overlookmotel/sequelize-virtual-fields.png)](https://david-dm.org/overlookmotel/sequelize-virtual-fields)

API is stable. All features and options are fairly well tested. Works with all dialects of SQL supported by Sequelize (MySQL, Postgres, SQLite).

Requires recent master of Sequelize v2.x dev branch, more recent than 28 Oct 2014. This is more recent than v2.0.0-rc2 which is latest available on NPM. i.e. you need to get latest Sequelize from Github.

## Usage

### Loading module

To load module:

	var Sequelize = require('sequelize-virtual-fields')();
	// NB Sequelize must also be present in `node_modules`

or, a more verbose form useful if chaining multiple Sequelize plugins:

	var Sequelize = require('sequelize');
	require('sequelize-virtual-fields')(Sequelize);

### Defining virtual fields

Define the dependency of the virtual fields on other attributes or models:

	// define models
	var Person = sequelize.define('Person', { name: Sequelize.STRING });
	var Task = sequelize.define('Task', {
		name: Sequelize.STRING,
		nameWithPerson: {
{'fraction_non_alphanumeric': 0.09536494405966968, 'fraction_numerical': 0.005860415556739478, 'mean_word_length': 4.776923076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4165358', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1076, 'n_words': 421}