Last active
August 29, 2015 14:07
-
-
Save jakobdamjensen/6b483b3bb06c06fcc3e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var knex = require('knex')({ | |
client: 'pg', | |
debug: true, | |
connection: { | |
host: 'localhost', | |
//user: 'your_database_user', | |
//password: 'your_database_password', | |
database: 'ecare_dump_db', | |
charset: 'utf8' | |
} | |
}), | |
bookshelf = require('bookshelf')(knex), | |
Region = bookshelf.Model.extend({ | |
tableName: 'regions', | |
published_documents: function () { | |
return this.belongsToMany(PublishedDocument).through(PublishedDocumentRegion, 'region_id', 'published_document_id'); | |
} | |
}), | |
PublishedDocumentRegion = bookshelf.Model.extend({ | |
tableName: 'published_document_regions' | |
}), | |
PublishedDocument = bookshelf.Model.extend({ | |
tableName: 'published_documents', | |
regions: function () { | |
return this.belongsToMany(Region).through(PublishedDocumentRegion, 'published_document_id', 'region_id'); | |
} | |
}); | |
new PublishedDocument().regions().query({where: {'regions.id': 1}}).fetch({withRelated: 'regions'}).then(function (collection) { | |
console.log("length: ",collection.length); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment