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

Can't load model within content type builder - cannot read property attributes of undefined #1749

Closed
MartinMuzatko opened this issue Aug 14, 2018 · 8 comments
Assignees

Comments

@MartinMuzatko
Copy link
Contributor

MartinMuzatko commented Aug 14, 2018

Informations

  • Node.js version: 10.8.0
  • npm version: 6.2.0
  • Strapi version: v3.0.0-alpha.13.1
  • Database: postgres
  • Operating system: Ubuntu Linux/WSL

What is the current behavior?

When loading the content type builder for a model, I get the following error:

[2018-08-14T15:07:38.403Z] debug GET /content-type-builder/connections (108 ms)
TypeError: Cannot read property 'attributes' of undefined
    at _.forEach (~/test-strapi/plugins/content-type-builder/services/ContentTypeBuilder.js:90:130)
    at ~/test-strapi/plugins/content-type-builder/node_modules/lodash/lodash.js:4925:15
    at baseForOwn (~/test-strapi/plugins/content-type-builder/node_modules/lodash/lodash.js:3010:24)
    at ~/test-strapi/plugins/content-type-builder/node_modules/lodash/lodash.js:4894:18
    at Function.forEach (~/test-strapi/plugins/content-type-builder/node_modules/lodash/lodash.js:9342:14)
    at Object.getModel (~/test-strapi/plugins/content-type-builder/services/ContentTypeBuilder.js:76:7)
    at getModel (~/test-strapi/plugins/content-type-builder/controllers/ContentTypeBuilder.js:27:31)
    at dispatch (/usr/lib/node_modules/strapi/node_modules/koa-router/node_modules/koa-compose/index.js:44:32)
    at next (/usr/lib/node_modules/strapi/node_modules/koa-router/node_modules/koa-compose/index.js:45:18)
    at dispatch (/usr/lib/node_modules/strapi/node_modules/koa-compose/index.js:42:32)
    at policies.push (/usr/lib/node_modules/strapi/lib/middlewares/router/utils/routerChecker.js:59:26)
    at dispatch (/usr/lib/node_modules/strapi/node_modules/koa-compose/index.js:42:32)
    at module.exports (~/test-strapi/plugins/users-permissions/config/policies/permissions.js:24:20)
[2018-08-14T15:07:38.452Z] debug GET /content-type-builder/models/pagemodule? (148 ms)

Then the page prompts me to create new fields, when the overview page says it already has 4 fields.

Steps to reproduce the problem

Create a model with the following attributes:

{
  "connection": "default",
  "collectionName": "pagemodules",
  "info": {
    "name": "pagemodule",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": true,
    "comment": ""
  },
  "attributes": {
    "name": {
      "type": "string"
    },
    "config": {
      "type": "json"
    },
    "pages": {
      "collection": "page",
      "via": "pageModules",
      "dominant": true
    },
    "pageModuleType": {
      "model": "pageModuleType"
    }
  }
}

If required, please let me know if the other models are also required to debug this.

What is the expected behavior?

load the fields for editing

Suggested solutions

This is the affected line of the function: getModel of plugins/content-type-builder/services/ContentTypeBuilder.js

params.targetColumnName = _.get((params.plugin ? strapi.plugins[params.plugin].models : strapi.models )[params.target].attributes[params.key], 'columnName', '');

It looks like you will always expect to have a params.target and that model has one.
To me, this looks like the model - when created, was misconfigured.

@MartinMuzatko MartinMuzatko changed the title Can't load Can't load model within content type builder Aug 14, 2018
@MartinMuzatko MartinMuzatko changed the title Can't load model within content type builder Can't load model within content type builder - cannot read property attributes of undefined Aug 14, 2018
@MartinMuzatko
Copy link
Contributor Author

Funny.
Now I removed the field from the model, and added it back via the content type builder.
The model is now named differently, in lowercase:

"pageModuleType": {
    "model": "pagemoduletype"
}

@lauriejim lauriejim self-assigned this Aug 20, 2018
@lauriejim
Copy link
Contributor

Hello @MartinMuzatko I think you issue is related to this issue #1139
Please try to lowercase your relations attributes.

@MartinMuzatko
Copy link
Contributor Author

Maybe partially. I see that when I use lowerCamelCase, that there are always all lowercase attributes added, that I did not add.

Model:
image

Response:
image

@derrickmehaffy
Copy link
Member

@lauriejim wouldn't it just be best to make sure model callbacks are always lowercase as to not mess with the field case? something like field.tolowercase()

@MartinMuzatko
Copy link
Contributor Author

I wouldn't mind if strapi would force me into a specific schema, since the default fields created_at and updated_at already use underscores, maybe fields using lowerCamelCase could be transformed in this. But having this mixed is a mess :/

@derrickmehaffy
Copy link
Member

I agree @MartinMuzatko there was some discussion on this a while back (for the life of me can't find the issue I created 😆 )

Everyone has different case types they normally use, I think honestly Strapi shouldn't limit users to a particular type and just handle the creation and management as far as needed, actual display values shouldn't be breaking thing (Both in the AdminUI and in the Rest/GraphQL response)

If I have a camelCase or a break_case being shown in the Rest strapi should handle these however it needs to in the backend (and database) but leave them in the frontend.

@derrickmehaffy
Copy link
Member

My original issue I outlined was the values displayed in the left menu, right now it can be quite ugly especially when it uses Plural values on things that should not be Plural.

@lauriejim
Copy link
Contributor

lauriejim commented Sep 17, 2018

I understand your need, I link this issue to this global models and attributes format issue - #1736

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants