Posted 15 October 2013 - 01:26 PM
"The value for the column "id" is not supplied when querying the table "tbl_courses".
I got XDEBUG working with my XAMPP server and stepped through the php calls, seeing what is going on inside the Yii engine. The ID is being transferred all the way down, to the CDBCommandBuilder:: createInCondition. I compared the code when it reached here for both programs (which works) and courses (which breaks). The difference is there are 2 ColumnNames with primary keys, my id (which is the one its supposed to point to, to bring up the specific course to view), and the foreign key (tbl_programs_id) which helps the courses know which program they belong to. I also use it to list only the courses that belong toa program.
So my question: I think I need foreign keys. There are lots of 1 to many relationships. Does Yii have limitations in working with complex INOUDB engines? I'm also kind of new with INOUDB, my first version used mysql MYISAM, which seemed easier because I was more familiar.
Well, I guess I need some pointers to how to use Yii/mysql/inoudb/foreign keys together, because I can't get passt this bug, and fear a major revision is necessary. And why is a foreign key being treated like a primary key.
Posted 15 October 2013 - 02:28 PM
The engine in MySQL your are talking about is called InnoDB, not InouDB. The main difference between InnoDB and MyISAM is that the first one supports transactions and foreign keys and is a little slower.
The main advantage of defining relations between tables using foreign keys is that you keep your data consistent. Those keys are called 'constraints' because they often prohibit modifying database in such way that would create "orphans", that is records in one table that relate to non existent records in other table. So you don't need to check it explicitly in your application. You can trust your database.
Foreign key constraints may seem annoying at first, because when you adjust your database structure while developing you often hit a lot of errors and can't perform queries fast. But with some experience you start to balance out when to use CASCADE, not null flags and even deffering triggers to keep your data consistent.
Posted 15 October 2013 - 07:28 PM
I have a primary id, which is just the number of the course. I also have a foreign key, that points to program that this course belongs to. But now when I use standard yii CRUD tools, I can manage all the courses (get a listing with the grid view widget , but I get an error when I try to 'view' one record, it gives me the exception, even though the id number is there. This is just using the standard infrastructure built by Yii.