question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relations broken when using format/parse

See original GitHub issue

Our build started breaking randomly today and I finally figured out that it was after the latest update of Bookshelf that you broke something related to ids.

All our tables use underscore as separator in the column names and camelCase in the models (As outlined in the example for model.parse).

One of our tables also uses one of these values as its ID attribute which has now broken relations for that table, fetches using withRelated for that table no longer return any results.

I have created the following gist: https://gist.github.com/richardsimko/fee44b444df3b3e768cdd530311dbd3d to illustrate the problem. Running broken.js will print the relation as length 0 and running working.js will print length 1. The only difference is the name of the ID attribute (clientKey vs client_key).

If I roll back to an earlier version than 0.10.3 both files work again.

EDIT: Thanks to installing from Git I have found that the issue started after #1397 was merged.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ricardogamacommented, Mar 7, 2017

I recommend Objection.js, it’s also based on knex and well documented and maintained.

1reaction
richardsimkocommented, Jan 23, 2017

The culprit is here: https://github.com/tgriesser/bookshelf/blob/1860604f57accdce19c6a1af0ef65bbdaf5b8531/src/relation.js#L398

If this.parentIdAttribute doesn’t match the name of the attribute in the target model it doesn’t work. Of course in this case they won’t match because obviously one is in snake_case and the other in camelCase.

At this point model is not an instance of my model but instead just an instance of BookshelfModel otherwise calling .parse on it could have worked.

Any workarounds are welcome as well as suggested fixes, I think I’ve done as much as I’m able to with my limited knowledge of the code base.

Actually on second though the behavior on that line has changed completely and I’m wondering if that may be an accident? It’s changed from model.id (I.e. the ID of the target model) to model.get(this.parentIdAttribute) (I.e. the ID of the parent model fetched from the target model). I may be wrong here but those aren’t supposed to be the same?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Foreign keys that don't reference foreign table primary key
Just ran into the following issue with relations which the foreign key does not target the foreign table primary key. Consider the use...
Read more >
Incorrect date parsing using SimpleDateFormat, Java
When I have string like "2011-06-12" as input in myDate I will get output "Thu Sep 29 00:00:00 EEST 2011", which is good....
Read more >
NetSuite Applications Suite - format.parse(options)
... Creating a Global Inventory Relationship Record · Processing Sales and Returns Using Intercompany Cross-Subsidiary Fulfillment · Warehouse Processing.
Read more >
GeneralLongTimePattern - Reference Source - Microsoft
UseHebrewRule = 0x00000008, // Format/Parse using the Hebrew calendar rule. UseSpacesInDayNames = 0x00000010, // Has spaces or non-breaking space in the day ...
Read more >
Maintaining Authenticated Communication in the Presence of ...
Abstract. We study the problem of maintaining authenticated communication over untrusted communication channels, in a scenario where the communicating ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found