Skip to content

belongTo isn't enough for "include" queries from other table #10974

Closed

Description

@demosglok

What are you doing?

Is it intended that sole "belongsTo" isn't enough to run queries on both sides

User.hasOne(Device)
Device.belongsTo(User)

i want to User.find({include:[Device]}) and Device.find({include: [User]})
but i need both relations (one per model) for that. I expected (according to docs) that single
hasOne or belongsTo is enough to run both queries, User.find and Device.find
To Reproduce
Steps to reproduce the behavior:

  1. Define models User, Device
  2. set belongsTo association: Device.belongsTo(User)
    run query from User side: User.find({include:[Device]})
  3. See error that User is not associated to Device

What do you expect to happen?

Users with their devices

What is actually happening?

User is not associated to Device

Environment

Dialect:

  • mysql
  • postgres
  • [ x] sqlite
  • mssql
  • any
    Sequelize version: 5.7.3
    Node Version: 10.x
    OS: window10

Activity

  1. papb commented on May 20, 2019

    @papb
    Member

    Hello :) Which part of the docs made you think that only one relation is enough? Sequelize can't infer the hasOne from the belongsTo because it could also be a hasMany for example.

  2. demosglok commented on May 20, 2019

    @demosglok
    Author
  3. papb commented on Jul 18, 2019

    @papb
    Member

    I will try to clarify the docs.

  4. self-assigned this
    on Jul 18, 2019
  5. added
    status: understood
    docs
    on Jul 26, 2019
  6. added
    status: wip
    and removed
    status: understood
    on Sep 6, 2019
  7. removed
    status: wip
    on Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docs

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions