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

Model scope method is not a function #727

Open
fiftoine opened this issue Jan 3, 2018 · 0 comments
Open

Model scope method is not a function #727

fiftoine opened this issue Jan 3, 2018 · 0 comments

Comments

@fiftoine
Copy link

fiftoine commented Jan 3, 2018

  • Platform: Windows 10 64-bit
  • Database: Mysql
  • Lux Version: 1.2.2
  • Node Version: 8.9.3

Considering this situation:

lux new testApp --database mysql
lux g resource user email:string password:string

Updated routes.js

this.resource('users', function () {
   this.post('/emails', 'emails');
});

Added scope to model

class User extends Model {
  static scopes = {
      findByEmail(email) {
          return this.first().where({
              email: email
          });
      }
  };
}

Added method to controller

class UsersController extends Controller {
  params = [
    'email',
    'password'
  ];

  query = [
      'data'
  ];

  emails({
      params: {
          data: {
              attributes: {
                  identification
              }
          }
      }
  }) {
    return User.findByEmail(identification);
  }
}

When I POST http://localhost:4000/users/emails with body
{"data":{"attributes":{"identification":"xxx@yyy.com"}}}

I receive a 500 with response :

{
    "errors": [
        {
            "status": "500",
            "title": "Internal Server Error",
            "detail": "User.findByEmail is not a function"
        }
    ],
    "jsonapi": {
        "version": "1.0"
    }
}

What is wrong in the situation for the method findByEmail not to be found?
This scope method should be callable from the controller no?

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