Multimodelform/jqrelcopy - Copy Previous Insert

Is there any easy way to copy my previous insert ? For example in demo: Insert group with 2 users with msg "Group with 2 members working on subject 1" for day 01-08-2013. Now I wanna copy that and get same values but now I will change msg and date.

How can I retrieve this data ? It can be like for group 1 I wanna define default values and then change them on update. Any idea ?

Cant you use $model->getPrimaryKey() and find the insert using findByPk if you are using model.

Just a wild guess. I could not understand your situation.

I just want to get values for my textfields from previous insert. I don’t want to write all over again. Copy and update, that’s all

How can I now get previous inserted id ?? I tried Yii::app()->db->getLastInsertID(); but it doesn’t work ;/

Sorry for late reply. I was away. For filling up text fields in your form there is a way which I can suggest as below.

This is only an idea. you may make the query. Query for the rows from the table you wanted, with limit=1 and condition as primary_key to be in descending order. You will get the last insert in that table.

Then fill all the required attributes of that row in advance to the new model you send to the form. It will fill the fields as per the last insert.

Hope this will be useful to you.

You can achieve it by

$model->setIsNewRecord(true);

set $model->primary_key=null;

your all values of attributes will be save again,change attributes values,whichever you want and save.

::)

Where should I set it ? In controller ??

I just can’t make it work. When I do something like


'data'=> $member->findAll('group_id=:group_Id', array(':group_Id'=>16)),

I can get what I want, but previous insert is deleted on save … (I change that group_id and that’s all -.-). I want to get it and insert new data and keep old one ;/