jbrumwell / mock-knex

A mock knex adapter for simulating a database during testing
MIT License
240 stars 71 forks source link

Working with relationships #47

Closed robinduckett closed 8 years ago

robinduckett commented 8 years ago

I'm currently working on building some tests around relationships of Bookshelf models. I have been using mock-knex but I'm not sure if it supports testing relationships. If this is possible, I'm having difficulty figuring out how.

Do I just add the "relations" field to my query response and try and guess what Bookshelf is expecting back?

jbrumwell commented 8 years ago

I've added a test, here is a simple example https://github.com/colonyamerican/mock-knex/pull/48/commits/be903bfc0fa8c431bb039e1a0657e294b64e462e#diff-b5633f4f0c413256b5a38e8ecc2f617dR85

robinduckett commented 8 years ago

Wow, thanks for your extremely fast example!

I am still having some trouble, with regards to "pivot" and how things are joined. If you could provide an example for that too, then that would be amazing

jbrumwell commented 8 years ago

@robinduckett if I get time I will and will link to it in this ticket. The best way is to add the relations you need the observe the query.sql in the tracker to determine what it is that it is looking for. Or alternatively run the same code on a live db and use those results to pass back in through the tests.