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

No record found #128

Closed
evgarik opened this issue Jun 17, 2017 · 1 comment
Closed

No record found #128

evgarik opened this issue Jun 17, 2017 · 1 comment

Comments

@evgarik
Copy link

evgarik commented Jun 17, 2017

Steps to reproduce

file ./products.hooks.js

function include() {
  return function (hook) {
    const productPrice = hook.app.service('product-prices').Model;
    const currencies = hook.app.service('currencies').Model;
    const edizm = hook.app.service('edizm').Model;

    const pricesShema = { model: productPrice,
      attributes: ['price', 'price_promo', 'price_card','publish'],
      include: [
        {
          model: currencies,
          attributes: ['title', 'socr']
        },
      ]
    };

    const edizmShema = { model: edizm,
      attributes: ['title', 'detail']
    };

    const association = { include: [edizmShema,pricesShema] };
    hook.params.sequelize = Object.assign(association,
      { raw: false });

    return Promise.resolve(hook);
  }
}

file ./product-prices.model.js

module.exports = function (app) {
  const sequelizeClient = app.get('sequelizeClient');
  const productPrices = sequelizeClient.define('productPrices', {
     ........
    }, {

      defaultScope: {
        where: {
          publish: true
        }
      },
      ..........
  });
...........................
  return productPrices;
};

If you run the query http://localhost:3030/products/6 then we get

{
    "name": "NotFound",
    "message": "No record found for id '6'",
    "code": 404,
    "className": "not-found",
    "errors": {}
}

If the file ./product-prices.model.js is removed

where: {
          publish: true
        }

run the query http://localhost:3030/products/6 then we get

{
    "id": 6,
    "title": "Milk",
    "count": "0.930",
    "edizm_id": 7,
    "product_tms_id": 1,
    "product_category_id": 3,
    "products_param_id": 0,
    "image": "milk_6.png",
    "detail": "",
    "sostav": "",
    "created_at": null,
    "updated_at": "2016-05-26T06:39:24.000Z",
    "productPrices": []
}

How to make that and in the first case the result with an empty value in the association be displayed.

Thanks for the help.

@evgarik
Copy link
Author

evgarik commented Jun 17, 2017

Found the answer himself
required: false,

const pricesShema = { model: productPrice,
      attributes: ['price', 'price_promo', 'price_card'],
      required: false,
      where: {
        publish: 1
      },
      include: [
        {
          model: currencies,
          attributes: ['title', 'socr'],

        },
      ]
    };

@evgarik evgarik closed this as completed Jun 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant