How to insert data in db using jsp?

Yii: How do I save many_many related data to mapping table?

  • I have three db tables, user (id, name), project (id, name) and map_user_project (user_id, project_id). I have tried ALL of the extensions for saving related data to tables, but none can seem to do what I need, which is very simple really! A user creates a project with a name, this gets saved easily, but I can't seem to insert a user_id & project_id into my mapping table (map_user_projects). It's confusing the hell out of me because its so simple, and I could have it done in 5 minutes using my own code, but I want to learn Yii. I'm currently using this to get records: $criteria->join = 'RIGHT JOIN map_user_project m ON t.id = m.project_id AND m.user_id=' .Yii::app()->user->id; and this to create them: $q = "INSERT INTO map_user_project (user_id, project_id) VALUES (" .Yii::app()->user->id .", $model->id)"; Yii::app()->db->createCommand($q)->execute(); I thought this would have been taken care of by the framework, after defining relations and foreign keys etc..?

  • Answer:

Cherif Bouchelaghem at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.