feat: Reference to the current instance of a related query
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, node.js
Research direction
Start by tracing the Relationship configuration and its beforeInsert hook, then inspect relationMappings and the ManyToManyRelation path shown in the example. Done means the hook can identify the model creating the relationship, allowing values such as fromModel.id to be used as requested.
Written by the indexing model from the issue text.
Description
It feels like there is missing context in the beforeInsert function set in a Relationship configuration. My biggest question is: Who is making this relationship?. I am looking to use a reference to the model that is creating a relationship so that I can answer that question in my DB. See example / pseudocode:
export class User extends Model {
static tableName = 'users';
// eslint-disable-next-line require-jsdoc
static relationMappings: RelationMappings = {
tags: {
modelClass: __dirname + '/Tag',
relation: Model.ManyToManyRelation,
join: {
from: 'users.id',
through: {
from: 'user_tags.user_id',
to: 'user_tags.tag_id',
},
to: 'tags.id',
},
beforeInsert(fromModel: User, toModel: Tag, ctx) {
toModel.created_by_id = fromModel.id; // <--- would be great if I could do this
}
}
};
}
There are a lot of other useful things that can be accomplished with this as well.
- Dominant language
- JavaScript
- Stars
- 7.3k
- Forks
- 637
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Vincit/objection.js
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Vincit/objection.js#2749 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Vincit/objection.js#2812 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
Vincit/objection.js#2811 ·
-
Project still alive? Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
Vincit/objection.js#2807 · 4 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 20/100
Vincit/objection.js#2805 ·
All issues in Vincit/objection.js
Similar issues
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100