javascript - BookshelfJS belongsToMany doesn't return duplicates -


i have 2 tables have relationship belongstomany. pivot table contains column called state have 3 different values. tables table1 , table2.

there can multiple entries same table1-table2 relation different states.

i want pivot entries table1 including multiple entries same table2.

unfortunately, code

return this.belongstomany(table2, 'pivot_table1_table2').withpivot(['state']) 

only returns first entry each table2.

help appreciated.

that's how bookshelf works! it's part of feature: remove dupes. found workaround; explicitly select attribute junction table that's unique. if don't have one, create model junction table. that's sadly solution then.

update:

perhaps that. routes.code unique in case , part of junction table. if won't trick, create model junction table , you're set (this more preferred).

new station().where({     id: req.params.id }).fetch({     withrelated: [{         'routes': function(qb) {             qb.select('routes.id', 'routes.code');         }     }] }).then(function(result) {     res.json(result.tojson()); }); 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -