More info: I have two tables TableA and TableB, I then have a form collecting data to populate TableA. TableB (attributeId) is a related table to TableA, hence the foreign key mentioned originally.
where attributeId is the foreign key everything works just fine. However there is another attribute in TableB (otherAttribute ) that I want the users to enter in the form but still have attributeId entered in TableA.
More info: I have two tables TableA and TableB, I then have a form collecting data to populate TableA. TableB (attributeId) is a related table to TableA, hence the foreign key mentioned originally.
where attributeId is the foreign key everything works just fine. However there is another attribute in TableB (otherAttribute ) that I want the users to enter in the form but still have attributeId entered in TableA.
First, you must add a new field to the model (public $otherAttribute). Then create a text field for it. You can use CExistValidator to check if the entered value exists in the related table. If yes, then in beforeSave() find this value and set model’s attributeId. Or you can set it to NULL otherwise.