Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing FROM clause entry for table...? #248

Closed
kerimdragolj opened this issue Nov 8, 2018 · 3 comments
Closed

Missing FROM clause entry for table...? #248

kerimdragolj opened this issue Nov 8, 2018 · 3 comments
Labels

Comments

@kerimdragolj
Copy link

kerimdragolj commented Nov 8, 2018

I was following these instructions for generating query in isolation. And I'm not sure if I did it right way but i made it work, it does what its required to. But when I copy that same code into before hook I get this error: missing FROM-clause entry for table...

Code inside of test.js which works and gives right resoult:


const app = require('./src/app');
app.setup();
const seqClient = app.get('sequelizeClient');
const model = seqClient.models['events'];
const log = console.log.bind(console);

model.findAll({
    where: {
        $or: [
            {
                creatorId: '4'
            },
            {
                '$participants.id$': '4'
            }
        ]
    },
    include: [
        {
            model: seqClient.models['users'],
            as: 'participants'
        }
    ],
}).then(log).catch(log);

Same code in hooks which gives that error:

const { authenticate } = require('@feathersjs/authentication').hooks;

function includeBefore(hook) {
  currUserId = hook.params.user.id;
  userModel = hook.app.services.users.Model
  hook.params.sequelize = {
    where: {
      $or: [
        {
          creatorId: '4'
        },
        {
          '$participants.id$': '4'
        }
      ]
    },
    include: [
      {
        model: userModel,
        as: 'creator',
      }, {
        model: userModel,
        as: 'participants',
      }
    ],
  }
  return hook;
}



module.exports = {
  before: {
    all: [
      authenticate('jwt'),
      hook => includeBefore(hook)
    ],
    find: [],
    get: [],
    create: []
.........

Is this right way to do it? What am I doing wrong?
Related question posted also on Stackoverflow.

@kerimdragolj
Copy link
Author

kerimdragolj commented Nov 10, 2018

I've found my answer here . Not sure why or how it works but adding duplicating: false in include did the trick. So now it looks like this:

function includeBefore(hook) {
  currUserId = hook.params.user.id;
  userModel = hook.app.services.users.Model
  hook.params.sequelize = {
    where: {
      $or: [
        {
          creatorId: '4'
        },
        {
          '$participants.id$': '4'
        }
      ]
    },
    include: [
      {
        model: userModel,
        as: 'creator',
      }, {
        model: userModel,
        as: 'participants',
        duplicating: false
      }
    ],
  }
  return hook;
}

Closing...

@kerimdragolj
Copy link
Author

kerimdragolj commented Nov 18, 2018

Seems it fixed this error, but strange behavior occurred.. I'm trying to combine order and duplicating, In my db i have 126 rows of participants, I set limit to 25, and in some calls i receive 24 even there is more than that to collect... Even in the first call to api (0-25) it returns just 24 rows, and in next one it goes 25-50 and returns 25.. its like it just skips some rows... I know this is not connected to row itself cause when I sort the other way (asc/desc) the row that wasnt shown previously now gets shown but some other disappears, this doesnt happen in every request... It might be connected to the limit cause when this happens its always the last row or last few rows in request thats missing!

Id love explanation on what this 'duplicating: false' does, what is not being duplicated?

@stale
Copy link

stale bot commented Mar 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Apologies if the issue could not be resolved. FeathersJS ecosystem modules are community maintained so there may be a chance that there isn't anybody available to address the issue at the moment. For other ways to get help see here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant