strapi icon indicating copy to clipboard operation
strapi copied to clipboard

Reviews Models and Attributes format

Open dsheyp opened this issue 8 years ago • 46 comments

Informations

  • Node.js version: v10.0.0
  • npm version: 5.6.0
  • Strapi version: 3.0.0-alpha.12.1.2
  • Database: mongodb
  • Operating system: Windows 10 64

What is the current behavior? After creating relation between content-types, strapi doesn't restart. Console says:

[2018-05-07T14:46:37.554Z] error Something went wrong in the model Container with the attribute contents [2018-05-07T14:46:37.557Z] error Cannot read property 'models' of undefined

Steps to reproduce the problem Do everything in the strapi UI and always choose the defaults that strapi suggests.

Create two content types "Container" and "Content". They both have a field "Title". Add a relation to "Container": One "Container" belongs to many "Content". Then save. Strapi wants to restart. Restart will not happen. Console says:

[2018-05-07T14:46:37.554Z] error Something went wrong in the model Container with the attribute contents [2018-05-07T14:46:37.557Z] error Cannot read property 'models' of undefined

What is the expected behavior? Strapi should restart and approve my content-types with their relation.

Suggested solutions I also did the following, which worked: I created content-type "Container", then added the relation to "Container": One "Container" belongs to many "User". I tried it because in the Content-Type-Manager when creating a relation to "User" things are displayed differently than with my own content-types. When i choose "User", then the title of the selector dropdown will also show "User (User-permissions)" but when i choose "Content" the title of the selector dropdown will just be blank. I'm not sure if it has something to do with that bug.

I tried again: Again everything was the same as described above. But then i tried to do the relation "the other way around": I added the relation to "Content": One "Container" has many "Content". It worked. And also the title of the selector dropdown will never be blank and always shows the correct content-type.

I have currently no suggestion how to solve this.


  • [x] I'm sure that this feature hasn't already been referenced.

dsheyp avatar May 07 '18 15:05 dsheyp

Same problem...

owengombas avatar May 08 '18 07:05 owengombas

@dsheyp Can you try to downgrade to Node v9 and test, I don't believe any testing has been done on Node v10 and it could be whats causing this.

derrickmehaffy avatar May 08 '18 09:05 derrickmehaffy

Hello @dsheyp I tried and it works on my side. Can you try with the last version of Strapi.

Can you share with me your 2 models please.

lauriejim avatar May 08 '18 09:05 lauriejim

I updated Strapi to the latest version but as I got things working for me with the "relation the other way round" I don't want to downgrade Node - this is too much change @ the moment - I have to go on with my Strapi-based project, someone is waiting for it ;-) So I kept my current project and added the two content-types as described above. The problem persists. Strapi can't restart. I have to remove the content-types manually from the filesystem and from mongodb. Only then Strapi can restart. Still exactly the same message in the console as described.

Hi @lauriejim I put the models on https://github.com/dsheyp/strapi-models as they were created by the Content-Type-Manager

I added a Screenshot showing the dropdown title being blank.

Added: I didn't have to remove the models from mongodb. Nothing was created in mongodb by the content-type-manager. Just in the filesystem.

dsheyp avatar May 08 '18 11:05 dsheyp

Exactly the same problem, the relations is created in one of ....settings.json model files but not on the second file, so I need to add this manually in the other file...

capturea captureb

owengombas avatar May 08 '18 12:05 owengombas

I have Node 9.11.1 and i'm experiencing the same issue so i don't think downgrading would change anything

cece95 avatar May 08 '18 12:05 cece95

This seems to appear at random, as I've done tests that it works fine, and others that will duplicate this exact same error. It seems to break when writing to one side of the relation.

derrickmehaffy avatar May 08 '18 16:05 derrickmehaffy

What I discribed earlier happened again. This time I tried to manually fix the models. I had to insert a relation. It still didn't work. There was one field plugin: " " When I removed that empty field it worked. Could the reason for this bug be found in that empty plugin: " " field?

dsheyp avatar May 08 '18 19:05 dsheyp

Seeing that there is problem with the plugin: " " attribute, I just want to mention that this may be related to #886. The fix is going to be released in alpha.12.2

XcrossD avatar May 09 '18 03:05 XcrossD

It seems to be a duplicate of https://github.com/strapi/strapi/issues/886. It has been fixed (https://github.com/strapi/strapi/pull/1081) but not released yet.

Aurelsicoko avatar May 09 '18 09:05 Aurelsicoko

Thanks @Aurelsicoko, So I'm waiting for 12.2 release. :wink:

mnlbox avatar May 09 '18 16:05 mnlbox

@Aurelsicoko I'm having this issue in 12.2 when creating a relation.

Mr-Black-Dahlia avatar May 20 '18 00:05 Mr-Black-Dahlia

@Aurelsicoko I also confirm that this issue still exists in 12.2. :thinking: I add some relation and my server stopped after save and not working at all. Please reopen this issue for more info.

/CC: @soupette, @lauriejim

mnlbox avatar May 22 '18 06:05 mnlbox

@mnlbox & @indiecore-fm Did you try with a fresh new application ?

lauriejim avatar May 22 '18 08:05 lauriejim

@lauriejim Yes, I create new app and copy my api folder in new app and then login to dashboard and create my relations. I follow this migration guide but replace 3.0.0-alpha.11.1 by 3.0.0-alpha.12.2 https://strapi.io/documentation/migration/migration-guide-alpha-10-to-alpha-11.html

mnlbox avatar May 22 '18 09:05 mnlbox

@mnlbox there is a breaking change on services code of your generated API. Please check https://github.com/strapi/strapi/wiki/migration-guide-alpha.12.1-to-alpha.12.2 for APIs migration

lauriejim avatar May 22 '18 14:05 lauriejim

I tested this out as well with a fresh installation. Unfortunately, it seems that a new bug has appeared. It has a different error message from what I have experienced before.

[2018-05-25T01:51:46.804Z] error Something went wrong in the model `Testspecification` with the attribute `test`
[2018-05-25T01:51:46.807Z] error Cannot read property 'hasOwnProperty' of undefined

I'm guessing this has to do with not checking for whether the object actually exists or not, judging from Object.hasOwnProperty.

XcrossD avatar May 25 '18 02:05 XcrossD

@Xcross I think it's a old issue because I see it 4 month later until now. I think Strapi need more robust code review specially about relation part of framework. It's related issues for more info: #734 #802 #886 #1081 #1143

mnlbox avatar May 25 '18 06:05 mnlbox

@mnlbox the problem is, the strapi team also need to be provided with the exact ways in which to reproduce the error to help track down the cause.

derrickmehaffy avatar May 25 '18 06:05 derrickmehaffy

@mnlbox I opened #886. The error I experienced and the issues you provided all point to this error message Cannot read property 'models' of undefined, which I believe is fixed in this current state by removing the plugin attribute. Now this different error message appeared without plugin so I think this is a new bug, unless the code behind all these is fundamentally flawed.

XcrossD avatar May 25 '18 07:05 XcrossD