Skip to content

Model scope method is not a function #727

@fiftoine

Description

@fiftoine
  • 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions