Skip to content

Column aliasing on RelationMapping.RelationJoin.RelationThrough.extra to avoid name collisions? #223

@newhouse

Description

@newhouse

First let me say that so far I'm very much liking Objection.js. It's got a lot of raw power, with a lot less bloat than other ORMs while still maintaining plenty of great conveniences (like RelationMapping). I've recently chosen it over Sequelize and Bookshelf (after migrating prior work from Mongo(ose)). It's great!

One handy feature I'm leveraging is the ability to provide modelClass and extra options when creating relationMappings that go through a join table. It's really useful to fetch information from a join table on your way through!

The problem I've encountered is when I put a column, say created_at into my extra array but a column with that name exists on both the RelationJoin.to and RelationThrough.to tables. It appears that in this case the related objects that are returned are using the value from the RelationThrough.to / extra table. In this example, I would want to have both created_at values as properties on the returned objects somehow. Perhaps allowing for aliasing the extra columns? e.g.:

// Suggestion 1:
extra: [ { 'created_at': 'join_table_created_at' }, { 'col_with_name_collision': 'non_colliding_name' } ];
// Suggestion 2:
extra: { 'created_at': 'join_table_created_at', 'col_with_name_collision': 'non_colliding_name' };

Oh, and trying to keep this also true at the same time would be great:

Columns listed here are automatically joined to the related objects when they are fetched and automatically written to the join table instead of the related table on insert.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions