Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
bookshelf-relations
Advanced tools
Insert, update and remove relationships on your Bookshelf models. This plugin supports all relationship types: belongs-to, belongs-to-many has-one and has-many.
npm install bookshelf-relations --save
or
yarn add bookshelf-relations
hook | type | default | description |
---|---|---|---|
autoHook | Boolean | true | The plugin takes over everything for you and hooks into the Bookshelf workflow. |
allowedOptions | Array | - | An array of allowed model options the plugin passes on when executing Bookshelf queries. |
unsetRelations | Boolean | true | The plugin will unset the relations after they are detected (e.g. model.unset('tags') ). If you are disabling "autoHook", you manually need to unset the relations. |
editRelations | Boolean | true | If false value is passed in the plugin will not edit the properties of related models unless specified otherwise on model-level relationshipConfig through editable flag. |
extendChanged | String | - | Define a variable name and Bookshelf-relations will store the information which relations were changed. |
attachPreviousRelations | Boolean | false | An option to attach previous relations. Bookshelf-relations attaches this information as _previousRelations on the target parent model. |
hooks | Object | - |
Example: hooks: {belongsToMany: {after: Function, before: Function}} |
Take a look at the plugin configuration in Ghost.
Hooks can be defined globally on the plugin options as described above, or they can be defined on a model by model basis. A model hook will replace a global hook if present - only one of them will run.
Hook should have a structure like so:
hooks: {
belongsToMany: {
before() {},
after() {}
}
}
The hooks we support are:
belongsToMany
before
/ beforeRelationCreated
after
/ afterRelationCreated
Either name can be used but the shorter name will be preferred if both exist.
The plugin will automatically deal with relationships upserts and cascading deletions through hasMany relationships. It's required to register your relationships in Bookshelf before you can use bookshelf-relations, see this example.
bookshelf.plugin('bookshelf-relations', {options});
bookshelf.Model.extend({
relationships: ['tags', 'news']
}, {...});
To opt-out of automatic child record deletion for hasMany
relationships it's possible to define per-relationship config:
bookshelf.Model.extend({
relationships: ['tags', 'news', 'events'],
relationshipConfig: {
events: {
destroyRelated: false
}
}
});
To opt-in for automatic relation editing pass in editable
flag in per-relationship config:
bookshelf.Model.extend({
relationships: ['tags', 'news', 'events'],
relationshipConfig: {
tags: {
editable: true
}
}
});
You manually need to call the plugin to update relationships. It's required to register your relationships in Bookshelf before you can use bookshelf-relations, see this example.
bookshelf.plugin('bookshelf-relations', {options});
bookshelf.manager.updateRelations({
model: model,
relations: {tags: [...]},
pluginOptions: {options}
})
// will detach & remove all existing relations
model.set('tags', []);
// will check if "test" exists and if not, it will insert the target tag
// will remove all previous relations if exist
model.set('tags', [{slug: 'test'}]);
yarn test
to run tests & eslintyarn lint
to run eslint onlyNODE_ENV=testing-mysql yarn test
to run tests with mysql dbyarn perf
to run a performance testyarn coverage
to run test coverageyarn ship
Copyright (c) 2013-2023 Ghost Foundation - Released under the MIT license.
FAQs
Auto update relations
The npm package bookshelf-relations receives a total of 2,416 weekly downloads. As such, bookshelf-relations popularity was classified as popular.
We found that bookshelf-relations demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 32 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.