Skip to content

Querying through relations #76

Open
@scott-taj

Description

@scott-taj

I've been working on upgrading all of my js-data stuff to v3 and I've run into an issue with querying through relations. I'm using js-data/js-data-http (both v3) on the front end and js-data/js-data-sql (both v3) on my API. I have two mappers:


const User = db.dataHealth.store.defineMapper({
  name: 'user',
  tableName: 'user',
  relations: {
    belongsTo: {
      reseller: {
        localField: 'reseller',
        foreignKey: 'reseller_id'
      },
      customer: {
        localField: 'customer',
        foreignKey: 'customer_id'
      }
    },
    hasMany: {
      login: {
        localField: 'logins',
        foreignKey: 'user_id'
      }
    }
  }
});

And


const Customer = db.dataHealth.store.defineMapper({
  name: 'customer',
  tableName: 'customer',
  relations: {
    hasMany: {
      user: {
        localField: 'user',
        foreignKey: 'customer_id'
      },
      account: {
        localField: 'accounts',
        foreignKey: 'customer_id'
      }
    },
    belongsTo: {
      reseller: {
        localField: 'reseller',
        foreignKey: 'reseller_id'
      },
      customer_type: {
        localField: 'customer_type',
        foreignKey: 'customer_type_id',
      }
    }
  }
});

In js-data v2, I was able to do queries like the following:

User.findAll({where: {user.customer.name: 'foo'}});

In js-data v3, queries like this produce the error

missing FROM-clause entry for table "customer"

I really need this functionality. Any suggestions? Thanks!

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