Skip to content

Instantly share code, notes, and snippets.

@rachaelshaw
Last active December 28, 2016 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rachaelshaw/f10d70c73780d5087d4c936cdefd5648 to your computer and use it in GitHub Desktop.
Save rachaelshaw/f10d70c73780d5087d4c936cdefd5648 to your computer and use it in GitHub Desktop.
Commented out stuff from sails-docs/concepts/ORM/Attributes.md

#1

primaryKey

Use this attribute as the the primary key for the record. Only one attribute per model can be the primaryKey. Note: This should never be used unless autoPK is set to false.

attributes: {
  uuid: {
    type: 'string',
    primaryKey: true,
    required: true
  }
}

#2

Move this into automigrations

size

If supported in the adapter, can be used to define the size of the attribute. For example in MySQL, size can be specified as a number (n) to create a column with the SQL data type: varchar(n).

attributes: {
  name: {
    type: 'string',
    size: 24
  }
}

#3

Omitting index from docs for now, because it is not officially supported in Sails v1 / Waterline 0.13. This could change in a future minor version release of Waterline (To get involved, please see http://sailsjs.com/contribute)

index

Will create a simple index in the underlying datastore for faster queries if available. This is only for simple indexes and currently dosn't support compound indexes. For these you will need to create them yourself or use a migration.

There is currently an issue with adding indexes to string fields. Because Waterline performs its queries in a case insensitive manner we are unable to use the index on a string attribute. There are some workarounds being discussed but nothing is implemented so far. This will be updated in the near future to fully support indexes on strings.

attributes: {
  email: {
    type: 'string',
    index: true
  }
}

#4

enum

A special validation property which only saves data which matches a whitelisted set of values.

attributes: {
  state: {
    type: 'string',
    enum: ['pending', 'approved', 'denied']
  }
}

#5

These are not ready for prime-time yet, but listing them here so they're easy to reference and add to official docs later:

example

An example value for this attribute, e.g. "Albus Dumbledore".

validationMessage

A custom validation message to use when any validations fail for this attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment