Coder Social home page Coder Social logo

loopback-counts-mixin's People

Contributors

exromany avatar jankcat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

loopback-counts-mixin's Issues

HasManyThrough relation - Error: Invalid relation type: undefined

I have the following relation,
file: grade.json

"relations": {
    "students": {
      "type": "hasMany",
      "model": "Account",
      "foreignKey": "gradeId",
      "through": "Family",
      "keyThrough": "studentId"
    },
    "mixins": {
      "Counts": true
    }
  }

Any request to /grades gives the following response:

{
    "error": {
        "statusCode": 500,
        "name": "AssertionError [ERR_ASSERTION]",
        "message": "Invalid relation type: undefined",
        "generatedMessage": false,
        "code": "ERR_ASSERTION",
        "actual": false,
        "expected": true,
        "operator": "==",
        "stack": "AssertionError [ERR_ASSERTION]: Invalid relation type: undefined\n    at validateRelation (/api/node_modules/loopback-datasource-juggler/lib/datasource.js:549:3)\n    at /api/node_modules/loopback-datasource-juggler/lib/datasource.js:515:7\n    at Array.forEach (<anonymous>)\n    at DataSource.defineRelations (/api/node_modules/loopback-datasource-juggler/lib/datasource.js:511:28)\n    at DataSource.setupDataAccess (/api/node_modules/loopback-datasource-juggler/lib/datasource.js:648:8)\n    at DataSource.attach (/api/node_modules/loopback-datasource-juggler/lib/datasource.js:882:8)\n    at Function.ModelClass.attachTo (/api/node_modules/loopback-datasource-juggler/lib/model-builder.js:382:16)\n    at /api/server/server.js:57:29\n    at Layer.handle [as handle_request] (/api/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/api/node_modules/express/lib/router/index.js:317:13)\n    at /api/node_modules/express/lib/router/index.js:284:7\n    at Function.process_params (/api/node_modules/express/lib/router/index.js:335:12)\n    at next (/api/node_modules/express/lib/router/index.js:275:10)\n    at nosniff (/api/node_modules/dont-sniff-mimetype/index.js:4:5)\n    at Layer.handle [as handle_request] (/api/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/api/node_modules/express/lib/router/index.js:317:13)"
    }
}

Counts Not working in Related Query

$scope.data = Institution.courses({
id: $stateParams.institution,
filter: {
include: 'institution',
counts:'batches'
}
});

Here Count is Not Returning..

add support for filter in headers

Hi, I'm currently using loopback3.x with Angular2. The current SDK generater generates codes with filter in header so that I can't use this package properly. Is it possible to add support for filter in headers?

It will returns 500, if the main entity is not find.

If I try to call GET /resource - it works clear, but if I try to call GET /resource/{id} with the mixin, I will get the error:

{
  "error": {
    "statusCode": 500,
    "message": "Internal Server Error"
  }
}

I think you should change the behavior of this case.

Hope it is clear for you. If you have questions, don't hesitate, ask me.

Returns 500 instead of 404 when parent object does not exist

Using the example from the readme, the following would return the "game" object corresponding to "id", with the added field of "playersCount":
http://0.0.0.0:3000/api/games/{id}?filter={"counts":"players"}

If a user were to invoke the following (assuming the id of 12345 does not exist in the db), loopback would return a 404.
http://0.0.0.0:3000/api/games/12345

However, when a user does the same call with a counts filter, loopback returns a 500 error.
http://0.0.0.0:3000/api/games/12345?filter={"counts":"players"}

"error": {
    "name": "TypeError",
    "status": 500,
    "message": "Cannot read property 'players' of null",
    "stack": "TypeError: Cannot read property 'players' of null
at ...node_modules/loopback-counts-mixin/counts.js:41:24
at Array.map (native)
at ...node_modules/loopback-counts-mixin/counts.js:40:36
at Array.map (native)
at fillCounts (...node_modules/loopback-counts-mixin/counts.js:39:34)
at injectCounts (...node_modules/loopback-counts-mixin/counts.js:16:5)
at Function.<anonymous> (...node_modules/loopback/lib/model.js:216:11)
at execStack (...node_modules/strong-remoting/lib/remote-objects.js:485:26)
at RemoteObjects.execHooks (...node_modules/strong-remoting/lib/remote-objects.js:497:10)
at phaseAfterInvoke (...node_modules/strong-remoting/lib/remote-objects.js:661:10)"
  }

Is it possible to add in a sanity check, so that if a 404 is going to be sent back we dont even try the counts? That way we still send back a 404?

How to filter by counts?

I'm using this mixin and wondering the easiest way to filter by the counts.

For example, I have a Post with a number of Ratings. I want to return a subset of Posts with a certain number of ratings, e.g.

Post.find({ where: { ratingsCount: { gt: 200 }}})

But this doesn't work, of course.

Is there a way to achieve this? Even with raw SQL?

Can I use it in nodejs query?

It works with REST api, but not works in remote method, how to add it to remote query?

Game.find({
counts:"players"
},cb)

This didn't work

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.