Skip to content

Updating extra in related query #413

@kacpak

Description

@kacpak

I've been struggling with updating extra field on many-to-many relation.
I have join table with user_id, session_id, character_id, is_game_master.

export default class User extends Model {
    static tableName = 'user';

    static relationMappings = {
        sessions: {
            relation: Model.ManyToManyRelation,
            modelClass: path.join(__dirname, 'session.model'),
            join: {
                from: 'user.id',
                through: {
                    from: 'character_session_user.user_id',
                    to: 'character_session_user.session_id',
                    extra: ['is_game_master', 'character_id']
                },
                to: 'session.id'
            }
        },
        character: {
            relation: Model.HasOneThroughRelation,
            modelClass: path.join(__dirname, 'character.model'),
            join: {
                from: 'user.id',
                through: {
                    from: 'character_session_user.user_id',
                    to: 'character_session_user.character_id',
                    extra: ['is_game_master', 'session_id']
                },
                to: 'character.id'
            }
        }
    };
}

I wanted to update character_id through related session.
I hope I was clear enough with what I want to accomplish.
What is the best way to accomplish that?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions