After adding Foreign Key Constraints to my Trongate app database, I am getting various errors like my some of my variables being undefined, and foreign key constraint errors upon submit.
My question is, should I remove my fk constraints and use the Module Relations in Trongate instead, or am I confusing the purpose of Module Relations?
Any guidance will be appreciated..
Cheers!
Module Relations vs MySQL / mariadb Foreign Key Contraints
4 years ago
4 years ago
#1
4 years ago
#2
Hi Keepcalm,
BTW, let's hope you are still 'keeping calm' :)
Firstly, I think you are confusing module relations with foreign key constraints. Without seeing your table structures and the way you are performing CRUD on each, it's a bit hard for me to speculate. Could you share some basic structure, and what you are trying to do?
In short, you must always work up from the lowest level of a table that has key restraints, otherwise the database will complain.
BTW, let's hope you are still 'keeping calm' :)
Firstly, I think you are confusing module relations with foreign key constraints. Without seeing your table structures and the way you are performing CRUD on each, it's a bit hard for me to speculate. Could you share some basic structure, and what you are trying to do?
In short, you must always work up from the lowest level of a table that has key restraints, otherwise the database will complain.
4 years ago
#3
Hi DaFa,
Yes I am keeping calm,
My project consists of a main table holding job assignment data, pulling employees , clients , client contacts , and report priorities data from related tables.
All tables were created using Trongate's module creator.
The main table uses integer id fields relating to the various tables and I created my own functions using Trongate's get() methods for dropdown options for the create() function, and Trongate's get_where() methods for the show() function.
I also modified the controller's manage() method adding left joins to retrieve the related tables' (non-integer) values.
In testing this worked fine but then I decided to add constraints as I usually do to maintain relational integrity, at which point errors started showing up on creating new and updating existing records in the main module.
I then realized that Trongate had it's own module relations feature, so I was wondering whether this should be used for things like related drop down lists instead of my custom functions.
Yes I am keeping calm,
My project consists of a main table holding job assignment data, pulling employees , clients , client contacts , and report priorities data from related tables.
All tables were created using Trongate's module creator.
The main table uses integer id fields relating to the various tables and I created my own functions using Trongate's get() methods for dropdown options for the create() function, and Trongate's get_where() methods for the show() function.
I also modified the controller's manage() method adding left joins to retrieve the related tables' (non-integer) values.
In testing this worked fine but then I decided to add constraints as I usually do to maintain relational integrity, at which point errors started showing up on creating new and updating existing records in the main module.
I then realized that Trongate had it's own module relations feature, so I was wondering whether this should be used for things like related drop down lists instead of my custom functions.
4 years ago
#4
Yes you can use the desktop app to create relationships for drop downs. There are two ways, one using a bridging table (this won't modify your tables) and the other will add columns to your tables.
4 years ago
#5
Thanks for the response DaFa,
Good info to know, I will experiment with this (the Modules Relations) on my next project,
I am happy with my own functions for now.
I am re-writing my create view and controller code and trying to figure out how to do a multi page( step 1 to step 2, etc) form type interface for my project as this would make the best use of space for my now ridiculously long data entry form.
I suspect that will mean more javascript, but I want something functional and looking nice so I don't mind.
Will keep you up to date.
Cheers!
Good info to know, I will experiment with this (the Modules Relations) on my next project,
I am happy with my own functions for now.
I am re-writing my create view and controller code and trying to figure out how to do a multi page( step 1 to step 2, etc) form type interface for my project as this would make the best use of space for my now ridiculously long data entry form.
I suspect that will mean more javascript, but I want something functional and looking nice so I don't mind.
Will keep you up to date.
Cheers!