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
Related Q & A:
- How can I save an Icollection in an object?Best solution by Stack Overflow
- How can I save photo attachments to Yahoo! Photos in mail beta?Best solution by ph.answers.yahoo.com
- How do I save/transfer old Yahoo email to my computer?Best solution by Yahoo! Answers
- How can I save money when I shopping at walmart?Best solution by Yahoo! Answers
- How can I save my data on the Internet?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.