ForestAdmin / forest-express-sequelize

🌱 Express/Sequelize agent for Forest Admin to integrate directly to your existing Express/Sequelize backend application.
https://www.forestadmin.com
GNU General Public License v3.0
191 stars 48 forks source link

Failure to create new item #320

Closed idahogurl closed 5 years ago

idahogurl commented 5 years ago

Expected behavior

Item is created without error

Actual behavior

Error is given and item is not created

Failure Logs

Terminal Logs Giving Foreign Key error because I do not allow NULL in country_id in the states table. image

Context

Network Panel is sending the id of the country image

Zip of my Models https://www.icloud.com/iclouddrive/0NawNHQCPitC0cdoh91KjEWeQ#models

Video showing steps & error https://youtu.be/7JncXAoVhMI

Package Version: 1.4.1 Express Version: 4.16.3 Sequelize Version: 5.8.11 Database Dialect: MySQL Database Version: 5.7.23

arnaudbesnier commented 5 years ago

Hi @idahogurl ,

It looks like your "states" model is badly configured. A state should belongsTo a country (instead of hasOne) if the countryId foreign key is on the states table. If I am right, this is not an issue of the Forest Liana, but a bad configuration on your side.

idahogurl commented 5 years ago

@arnaudbesnier I have tried belongsTo. Still is not working.

idahogurl commented 5 years ago

@arnaudbesnier The trick was that I needed to specify foreignKey = "countryId" and targetKey = "id" as well as changing to belongsTo. That would be good to add to your documentation.