Skip to content

format idAttribute on save/delete (#1676)#1680

Merged
ricardograca merged 4 commits into
bookshelf:masterfrom
osher:patch-2
Feb 8, 2018
Merged

format idAttribute on save/delete (#1676)#1680
ricardograca merged 4 commits into
bookshelf:masterfrom
osher:patch-2

Conversation

@osher

@osher osher commented Nov 2, 2017

Copy link
Copy Markdown
Contributor

format idAttribute on save/delete (#1676)

Introduction

Working with a DB and Web that do not agree on field-names conventions - trying to leverage Model#format() and Model#parse() worked for selects and inserts - but fails for udpates and deletes.

Motivation

This PR fixes that. Closes #1676, Closes #1338.

Proposed solution

use Model#format to transform the id attribute name passed to .where in delete and update operations.

Current PR Issues

none

Alternatives considered

none

@rapzo

rapzo commented Nov 2, 2017

Copy link
Copy Markdown
Contributor

I'll give a round on this, although, we could move the format up a bit instead of running it twice, even for a single key, it looks harder to read than it'd be with a single call.

@osher

osher commented Nov 8, 2017

Copy link
Copy Markdown
Contributor Author

Lost you there, you mean just to do it in two lines instead of one, or create a more reusable method and call it from there?

LMK - I'll comply

@osher

osher commented Nov 8, 2017

Copy link
Copy Markdown
Contributor Author

P.S - I met more bugs around the same problem which appears in different places around delete and updates, although I'm yet sure if the root cause is in Bookshelf itself, or in bookshelf-modelbase plugin.

I tend to go for creating a method that provides a selector/filter/where clause that should be used wherever a key to a table is needed.

Not just a private function, but a part of the API.
If all implementations will pull table key from this API - it will also make supporting compound keys in the future easy peasy

@osher

osher commented Nov 15, 2017

Copy link
Copy Markdown
Contributor Author

anything?

@ricardograca

Copy link
Copy Markdown
Member

I'm not that sure about increasing our dependency on .format() and .parse(), but I'm not contributing much code to the project anyway, so maybe someone more active can comment on this issue.

@ricardograca ricardograca left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very similar to #1338. Can you explain why your solution is better? Also, can you provide test cases for the issues this fixes?

@osher

osher commented Feb 6, 2018

Copy link
Copy Markdown
Contributor Author

Yup. looks very similar. I think mine uses less operations, but it's so negligible that it doesn't worth the discussion.
I don't care which of them you take, as long as the issue is fixed 👍 😉

@ricardograca ricardograca left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. This just needs a test case then and I'll merge it.

@osher

osher commented Feb 7, 2018 via email

Copy link
Copy Markdown
Contributor Author

@osher

osher commented Feb 8, 2018

Copy link
Copy Markdown
Contributor Author

ok, done. There you go 😃
@ricardograca - I think the ball is in your court again

Updated: Sorry it took so long, I misread the picture...

@osher

osher commented Feb 8, 2018

Copy link
Copy Markdown
Contributor Author

@ricardograca
Uh...
Is there something I have to do to handle the change-request except the commits I pushed?

@ricardograca

Copy link
Copy Markdown
Member

@osher Sorry, I'll take a look later today. Currently busy with something else.

@ricardograca ricardograca merged commit 9f0f243 into bookshelf:master Feb 8, 2018
@osher osher deleted the patch-2 branch February 11, 2018 09:14
@osher

osher commented Feb 11, 2018

Copy link
Copy Markdown
Contributor Author

+1 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.format(attr) is not applied to where clause on update?

3 participants