Skip to content

Find options nested where  #3902

Closed
Closed

Description

@onionhammer

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

According to the docs here,

Querying a column from an embedded entity should be done with respect to the hierarchy in which it was defined. Example:

userRepository.find({ where: { name: { first: "Timber", last: "Saw" } } });

For me the parameters inside of the nested object are simply missing from the query.

My example:

db.getRepostiory(device)
  .find({
    where: {
      group: { 
        id: groupId,
        account: { id: accountId }
      }
    }
  });

Here 'accountid' is left out of the generated query, and only 'groupId' is sent as a parameter.

Activity

  1. adamkrupke commented on Mar 28, 2019

    @adamkrupke

    What does the device schema look like? Is account an embedded entity?

  2. trixden commented on Mar 28, 2019

    @trixden

    #3890 same problem

  3. onionhammer commented on Mar 28, 2019

    @onionhammer
    Author

    @nomadoda Schema looks like this

    @Entity("devices")
    export class Device extends RootEntity {
    
      @ManyToOne(type => Group, group => group.devices, { onDelete: 'CASCADE', nullable: false })
      @JoinColumn({ name: "groupId" })
      group: Group
    
    }
    @Entity("groups")
    export class Group extends RootEntity {
    
      @OneToMany(type => Device, device => device.group, { cascade: true })
      devices: Device[]
    
      @ManyToOne(type => Account, account => account.groups, { onDelete: "CASCADE", nullable: false })
      @JoinColumn({ name: "accountId" })
      account: Account
    }
    @Entity("accounts")
    export class Account extends RootEntity {
    
      @OneToMany(type => Group, group => group.account, { cascade: true })
      groups: Group[]
    }

    Removed some columns for simplicity

  4. pie6k commented on Apr 17, 2019

    @pie6k

    I have the same issue

    My code:

            const deleteResult = await ListMembership.delete({
              list: { owner: { id: user.id } },
              user: { id: user.id },
            });

    Resulting query (from console):

    query: DELETE FROM "list_membership" WHERE "listId" = $1 AND "userId" = $2 -- PARAMETERS: [null,"a12580b9-9e1b-463c-9738-6b5591f97655"]
    

    It's quite weird.

  5. pie6k commented on Apr 17, 2019

    @pie6k

    Even more interesting - it's possible to 'destroy data':

    Code:

            const deleteResult = await ListMembership.delete({
              list: { id: Not(IsNull()), owner: { id: user.id } },
              user: { id: user.id },
            });

    Resulted in query:

    query: DELETE FROM "list_membership" WHERE NOT("listId" IS NULL) AND "userId" = $1 -- PARAMETERS: ["a12580b9-9e1b-463c-9738-6b5591f97655"]
    

    Which narrowed criteria and removed data I didnt want to remove here.

  6. a7urag commented on Apr 11, 2020

    @a7urag
  7. imnotjames commented on Oct 15, 2020

    @imnotjames
    Contributor

    Nested where in find is currently working. I had tested it in another issue. I'll be marking this one as a duplicate of that issue.

  8. imnotjames commented on Oct 15, 2020

    @imnotjames
    Contributor

    Duplicate of #2707

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions