mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
Define belongsToMany
foreign keys for tags in the model layer
no issue - otherwise we will have trouble in the future fetching relations by foreign key - e.g. `tag_id: {id}` - this won't work if we don't explicitly define the name of the keys - bookshelf can't fulfil the request - this does not change any behaviour, it just makes use of the ability to define the names of your foreign keys
This commit is contained in:
parent
b204d5874e
commit
12724df8e4
1 changed files with 3 additions and 1 deletions
|
@ -331,7 +331,9 @@ Post = ghostBookshelf.Model.extend({
|
|||
},
|
||||
|
||||
tags: function tags() {
|
||||
return this.belongsToMany('Tag').withPivot('sort_order').query('orderBy', 'sort_order', 'ASC');
|
||||
return this.belongsToMany('Tag', 'posts_tags', 'post_id', 'tag_id')
|
||||
.withPivot('sort_order')
|
||||
.query('orderBy', 'sort_order', 'ASC');
|
||||
},
|
||||
|
||||
fields: function fields() {
|
||||
|
|
Loading…
Add table
Reference in a new issue