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

Controller params default to empty array, not to serializer attributes #745

Open
CodingItWrong opened this issue Jun 18, 2019 · 0 comments

Comments

@CodingItWrong
Copy link

  • Platform: Darwin Joshs-MacBook-Pro-2.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
  • Database: sqlite
  • Lux Version: 1.2.3
  • Node Version: v10.15.3

The guides for Controller#params seem to indicate that it is optional:

If you do not override this property all of the attributes specified in the Serializer that represents a Controller's resource. If the Serializer cannot be resolved, this property will default to an empty array.

However, this defaulting doesn't seem to be working for me.

(Demo repo here: https://github.com/CodingItWrong/lux-test)

When I have the following Serializer and Controller with explicit params, I can successfully create a record with values passed in:

class RestaurantsController extends Controller {
  params = ['name', 'address'];
}
class RestaurantsSerializer extends Serializer {
  attributes = ['name', 'address'];
}

But if I remove Controller#params:

class RestaurantsController extends Controller {
}

Then upon POSTing a record I get empty attributes back:

POST:

{
  "data": {
    "type": "restaurants",
    "attributes": {
      "name": "Sushi Place",
      "address": "123 Main Street"
    }
  }
}

Response:

{
    "data": {
        "id": "3",
        "type": "restaurants",
        "attributes": {},
        "relationships": {
            "dishes": {
                "data": []
            }
        }
    },
    "links": {
        "self": "http://localhost:4000/restaurants"
    },
    "jsonapi": {
        "version": "1.0"
    }
}

And if I GET /restaurants/ I get null values for the attributes:

{
  "data": [
    {
      "id": "1",
      "type": "restaurants",
      "attributes": {
        "name": null,
        "address": null
      },
...
    }
  ],
...

}
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