Skip to content

Inconsistent create behavior when starting from hasMany vs belongsTo #8716

@geoffreak

Description

@geoffreak

Running version 4.23.2

Say I have two models, Parent and Child and an instance of each parent and child respectively. Parent hasMany Child and Child belongsTo Parent.

Why is it that the association create behavior is different when creating the other? I expected the new instance returned from each create call.

createChildResult = await parent.createChild()
// createChildResult is a new Child instance ✅

createParentResult = await child.createParent()
// createParentResult is the same child??? ❌
createParentResult === child // Why is this true???

The docs don't seem to cover this backwards behavior either. The return type is just listed as Promise with no types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugDEPRECATED: replace with the "bug" issue type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions