From bfe621cbe5eda7654c9c059a9f3673ff0d2e6986 Mon Sep 17 00:00:00 2001 From: Sascha Gehlich Date: Tue, 7 Jan 2014 13:07:22 +0100 Subject: [PATCH] Updated readme and changelog, v0.0.6 --- CHANGELOG.md | 7 +++++++ README.md | 25 ++++++++++++------------- package.json | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a857b9d..7fef2d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +0.0.6 (Jan 7 2014) +================== + +* Models now take a model as the constructor parameter instead of the sequelize model. All helpers will be called on that map. +* Added error message for missing association models +* Added a `modelMatch` option (can be a string, a regular expression or a function) + 0.0.5 (Jan 6 2014) ================== diff --git a/README.md b/README.md index 744e007..147138c 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Since `sequenice` is just a model wrapper for `sequelize`, you will have to init var Sequenice = require("sequenice") , new Sequenice(database, { modelsDirectory: __dirname + "/models", // The path to your models folder + modelsMatch: "**/*.js", // A string, regex or filter function for selecting the correct files modelsAttacher: global, // The object you want to attach your models to getterPrefix: "get", // See "Defining models" setterPrefix: "set", // See "Defining models" @@ -46,41 +47,39 @@ Inside the constructor you have access to a couple of helpers which will define Here's an example: ```js -function Product(s) { - // `s` points to the Sequelize module - +function Product(map) { // Field definitions - this.field("name", s.STRING); - this.field("isPublished", s.BOOLEAN, { defaultValue: false }); + map.field("name", s.STRING); + map.field("isPublished", s.BOOLEAN, { defaultValue: false }); // Associations // hasOne, belongsTo, hasMany // Pass the associated model name as a string. - this.hasMany("Variants"); - this.belongsTo("Category"); + map.hasMany("Variants"); + map.belongsTo("Category"); // Hooks // beforeValidate, beforeCreate, ... // Pass the method name as a string. - this.beforeCreate("publish"); + map.beforeCreate("publish"); // Getters / Setters // Define getterMethods and setterMethods. Pass the variable name // as a string. // If your getterPrefix is "get" and the variable name is "price", // sequenice will try to call the "getPrice" method of your class. - this.get("price"); - this.set("price"); + map.get("price"); + map.set("price"); // Validations // Pass the validation method name as a string. - this.validates("cheap"); + map.validates("cheap"); // Indices - this.index(["name", "isPublished"], { indexName: "NameIsPublished" }); + map.index(["name", "isPublished"], { indexName: "NameIsPublished" }); // Model options - this.options({ + map.options({ timestamps: false }); } diff --git a/package.json b/package.json index 6ab98ab..9c6148d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sequenice", - "version": "0.0.5", + "version": "0.0.6", "description": "A nice model wrapper for `sequelize`", "main": "index.js", "directories": {