Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync, Model methods differences? #43

Closed
amitava82 opened this issue Aug 13, 2013 · 2 comments
Closed

Sync, Model methods differences? #43

amitava82 opened this issue Aug 13, 2013 · 2 comments
Labels

Comments

@amitava82
Copy link

Model has query, save, fetch, destroy methods and Sync has similar methods (first, select, insert, update, del) as well. What's the difference between two or they can be used interchangeably?

To query I could use Model.query().where() or I can use sync.select([options])

@tgriesser
Copy link
Member

@amitava82 you actually don't want to use sync directly, it is really only documented for explanation purposes (in-case you want to extend) and primarily used internally. What you'll want to do is use save, fetch and destroy on the models/collections... if you need to use the query method, it's often to tap into the query chain for the current object.

// resolves with a Bookshelf model
model.query('where', 'id', '>', 30).fetch().then(...

// resolves with a response array, might as well be using Knex at this point
model.query().where('id', '>', 30).select().then(...

@amitava82
Copy link
Author

Got! Thanks! Might as well make a note of it in the doc. Newbies (like me :p) won't get confused. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants