# zero-relation

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

Latest version **0.0.10** (published 2014-11-28) · 0 weekly downloads

## Install

```sh
npm install zero-relation
pnpm add zero-relation
yarn add zero-relation
bun add zero-relation
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.10 |
| Published | 2014-11-28 |
| First published | 2014-10-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | jiamiu |
| Maintainers | sskyy |
| Keywords | zero module |

## Links

- npm: https://www.npmjs.com/package/zero-relation
- npm.io page: https://npm.io/package/zero-relation

## Recent versions

- 0.0.10 (latest) — 2014-11-28
- 0.0.9 — 2014-11-26
- 0.0.8 — 2014-11-18
- 0.0.7 — 2014-11-16
- 0.0.6 — 2014-11-09
- 0.0.5 — 2014-11-06
- 0.0.4 — 2014-11-06
- 0.0.3 — 2014-11-02
- 0.0.2 — 2014-10-29

## README

# 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"
		}
	}
}
```

2. 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.

3. 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
```

---
_Source: https://npm.io/package/zero-relation · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
