abrarazeem
(Abrarkiani)
December 30, 2010, 3:27pm
1
can we make A single model for Two tables(related, has-one) and How?
After Save of First table foreign key goes to second table and some detail
also?
OR
any way to insert data in two tables using single form? by using after save of first Model.
can we make A single model for Two tables(related, has-one) and How?
I dont think so, never tried but, why do you want such feature? Selection maybe? IF that is so, you can create a VIEW on your Database and then create a Model to work on AR but… I do not have a clue if, or not, when you save the AR you actually save on the VIEW and the connected tables RESPECTIVELY.
any way to insert data in two tables using single form? by using after save of first Model.
You can do it using event onAfterSave() for the model. In this function you can insert the data to the other table by using DAO or its correspondent Model (AR).
Cheers
abrarazeem
(Abrarkiani)
December 31, 2010, 6:54am
3
i want a single form to insert values into two tables related
one primary goes as foreign in second table
is there any way to do this?
help me i m stuck at this point…
andy_s
(Arekandrei)
December 31, 2010, 7:31am
4
I suggest you to use two models $model1 and $model2. Just pass both to a view and create inputs as usual:
$form->textField($model1, 'attribute1'); // or CHtml::activeTextField($model1, 'attribute1');
$form->textField($model2, 'attribute2'); // or CHtml::activeTextField($model2, 'attribute2');
After a form is submitted, save your models using $model1->save() and $model2->save().
There is a more “advanced” way to do that using form builder & nested forms, maybe you’ll like it more.
fouss
(Jsfousseni)
December 31, 2010, 7:33am
5
i want a single form to insert values into two tables related
one primary goes as foreign in second table
is there any way to do this?
help me i m stuck at this point…
You may also try this how to
abrarazeem
(Abrarkiani)
December 31, 2010, 1:50pm
7
andy_s:
I suggest you to use two models $model1 and $model2. Just pass both to a view and create inputs as usual:
$form->textField($model1, 'attribute1'); // or CHtml::activeTextField($model1, 'attribute1');
$form->textField($model2, 'attribute2'); // or CHtml::activeTextField($model2, 'attribute2');
After a form is submitted, save your models using $model1->save() and $model2->save().
There is a more “advanced” way to do that using form builder & nested forms, maybe you’ll like it more.
thanks man i’ll take a look
abrarazeem
(Abrarkiani)
December 31, 2010, 7:32pm
8
Thanks a lot Both andy_s and fouss
I got it working
kamran
(Kamran)
April 26, 2011, 7:30am
9
Hi, Abrar.
How did you get it working? Can u tell me?
U use two models or one?
kapous
(Hatemn2001)
April 7, 2014, 6:08am
10
I think using view is the best solution … I struggled two days in that problem until start to use views as Antonio Ramirez suggest
Thanks Antonio Ramirez