Skip to content

Join fields lost when using eager #341

@adiamini

Description

@adiamini

Model.query().select('pets.*')

returns correctly:

[{
    id_pet: 1,
    name: 'One'
},
{
    id_pet: 2,
    name: 'Two'
}]

When using eager like:

related: {
    relation: Model.HasOneRelation,
    join: {
        from: 'pets.id_pet',
        to: 'something.id_pet'
    }
}
Model.query().select('pets.*').eager('related')

This returns wrong, with missing field:

[{
    name: 'One',
    related: [{
        id_pet: 1,
        related_data: 'abc'
    }]
},
{
    name: 'Two',
    related: [{
        id_pet: 2,
        related_data: 'xyz'
    }]
}]

In this example, field id_pet is present in both main table and relation table, and when using eagers it disappears from main table's result.

Note: this is an example, you can try with BelongsToOneRelation or ManyToManyRelation, issue is the same.
Note 2: Just updated objection from 0.6.2 to 0.7.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions