How to Insret data in two table at once

I have two table namely ‘Cust_ac’ and ‘cust_info’, both are linked by acno (Account No.).

What I want is that I want to one from to enter data into both tables.

How and what should I do?

This wiki will give some ideas - http://www.yiiframework.com/wiki/291/update-two-models-with-one-view

Hello

You have to make model of both.

than $acc = new Cust_ac()// Cust_ac = Model name

$acc->field_name_1 = $_post[‘field_name_1’];

$acc->field_name_2 = $_post[‘field_name_2’];

$acc->save(false);

$info = new cust_info()// Cust_ac = Model name

$info->acno = $acc->acno;

$info->save(false);

Thanks

@ mdomba

@ Pravin Gajera

Thanks both for your help

if attributes of the two tables(models) are different then use saveAttributes() function…

Please clarify this statement. I didn’t get the use of saveAttributes() function in the topic’s case from your point of you.

Thank you.

if the second table contains different names other than first, and the values to be inserted is the same…

then

2nd-model->attributes=$_POST[‘1st-model’];

2nd-model->save();

these are not possible…

so we can use 2nd-model->saveAttributes(array(…));

I’ve got your idea for this special case, though don’t think I’ve ever encountered it. I couldn’t even make up a proper db structure for such a case, as usually you store value in one place only, in order to have a good database structure. Maybe I’m loosing some point.

Mostly it’s like you have different attributes and values in two tables and just want to gather them in one common form. And, I think, initially the topic’s question was about this case.

yeah…right…i think he need this idea too for ‘Account No’…any way i think he did it… :) :)