Replies: 1 comment
|
Ok, i resolved with this code. In Students.cfc (controller), edit() method: and in html: My question now is: is there a more elegant solution (using some framework's function, that i ignore) or the above is the most acceptable solution? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi all
This is the scenario
Table "students", table "masterlocations" and associative table "studentmasterlocations": one student can partecipate at one o more master on specific location and obsiouly one location can hospitate one o more students.
Tables:
CREATE TABLEstudents(idINT(11) NOT NULL AUTO_INCREMENT,firstnameVARCHAR(250) NOT NULL COLLATE 'utf8_general_ci',lastnameVARCHAR(250) NOT NULL COLLATE 'utf8_general_ci',createdatDATETIME NULL DEFAULT NULL,updatedatDATETIME NULL DEFAULT NULL,deletedatDATETIME NULL DEFAULT NULL, PRIMARY KEY (id) USING BTREE, ) COLLATE='utf8_general_ci' ENGINE=InnoDB AUTO_INCREMENT=46 ;CREATE TABLEstudentmasterlocations(studentidINT(11) NOT NULL,masterlocationidINT(11) NOT NULL,tutorTINYINT(1) UNSIGNED NOT NULL DEFAULT '0',createdatDATETIME NULL DEFAULT NULL,updatedatDATETIME NULL DEFAULT NULL,deletedatDATETIME NULL DEFAULT NULL, PRIMARY KEY (studentid,masterlocationid) USING BTREE, INDEXfk_studentsmasters_students1_idx(studentid) USING BTREE, INDEXfk_studentsmasters_masters1_idx(masterlocationid) USING BTREE, CONSTRAINTfk_studentsmasters_masters1FOREIGN KEY (masterlocationid) REFERENCESmasterlocations(id) ON UPDATE CASCADE ON DELETE CASCADE, CONSTRAINTfk_studentsmasters_students1FOREIGN KEY (studentid) REFERENCESstudents(id) ON UPDATE CASCADE ON DELETE CASCADE ) COLLATE='utf8_general_ci' ENGINE=InnoDB ;CREATE TABLEmasterlocations(idINT(11) NOT NULL AUTO_INCREMENT,nameVARCHAR(250) NULL DEFAULT NULL COLLATE 'utf8_general_ci',createdatDATETIME NULL DEFAULT NULL,updatedatDATETIME NULL DEFAULT NULL,deletedatDATETIME NULL DEFAULT NULL, PRIMARY KEY (id) USING BTREE) COLLATE='utf8_general_ci' ENGINE=InnoDB AUTO_INCREMENT=1 ;Those are the models
Student.cfc
component extends="Model" { function config() { hasMany(name = "studentmasterlocations"); nestedProperties(associations="studentmasterlocations", allowDelete=true); }Studentmasterlocation.cfc
component extends="Model" { function config() { belongsTo(name = "student"); belongsTo(name = "masterlocation"); } }Masterlocation.cfc
component extends="Model" { function config() { hasMany(name = "studentmasterlocations"); } }In the html form:
...
#hasManyCheckBox(objectName = "student", association = "studentmasterlocations", keys = "#student.key()#,#masterlocations.id#", label=" #masterlocations.locationname#")#...
All this code works fine: create, edit, update, ecc, without extra code.
Example code in controller Students.cfc -> edit():
student=model("student").findByKey(key=params.key, include="studentmasterlocations") masterlocations=model("masterlocation").FindAll(order="name");The "problem" is that i don't know how to manage field flag "tutor" on table "studentmasterlocations".
Must i manual manage this flag?
And if yes, how?
Thank
All reactions