0.0.10 • Published 9 years ago

zero-relation v0.0.10

Weekly downloads
37
License
-
Repository
-
Last release
9 years ago

zero-relation

This module use middle-collection to make relation between to models.

Usage

  1. Add dependency to your module package.json file like:
{
	"name" : "YOUR_MODULE_NAME",
	"zero" : {
		"dependencies" : {
			"relation" : "^0.0.1"
		}
	}
}
  1. Declare relation in model definition like:
module.modes = [
{
  identity: 'post',
  attributes: {
    title : 'string',
    content : 'string',
    category : 'array'
  },
  isNode : true,
  rest : true
},{
  identity : 'tag',
  attributes : {
    name : {
      type : 'string',
      unique : true
    },
    nodes : 'json'
  },
  relations : {
    posts :{
      model : "post",
      auth : ['read'],
      multiple : true,
      reverse : {
        name : "tags",
        index:"name",
        auth : ['read','write'],
        multiple : true
      }
    }
  },
  index : 'name',
  rest : true
}
]

Once you declared the relation between two model, this module will handler all relation creation of modification for you. For example above, if you create a post with parameter like:

{
	title : 'test',
	content : 'test',
	tags : [{name:'tag1'}, 2]
}

Relation module will create a new tag named tag1, and update tag's relation which id is 2.

  1. You can use populate to specify which relation record you want to fetch with current request. For example, you can fetch a post which id is 1 with all its tags using:
http://localhost/post/1?populate=tags
0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago