Passing Primary Key value to Foreign Key table on same form view

Hi Guys,

I am facing a problem passing value of primary key of parent table to the child table where it is foreign key. They are both on the same form and validated. But I am not able to find out how to solve this problem.

Any hints?

Thanking you in advance.

this works? update/create action in your control





if ($modelA->save()){

   $modelB->TableA_UniqueID = $modelA-> UniqueID;

   $modelB->save();

}






I imagine you’re stuck only with new records. In That case, don’t forget to refresh your model after saving so That the id field / property is correctly populated from the db, either it is an autoincrement pk or some other guid.


if($modelA->save()) {

  ...

  $modelA->refresh();

  $modelB->aId = $modelA->id;

  if($modelB->save()) {

    ...

  }

  ...

}

If you’re updating a record from Model A, I guess it already works smoothly.

@rootbear @bennouna

Thanks to both for your response to my post. Both of the above are really helpful. Based on the information provided by you both, I believe the problem is definately solved because I can clearly see it is making an absolute sense.

I will update you anyway.

Many thanks once again.

Hi Yasir,

how was it? which one is working for u?

thanks.

thanks rootbear. solved my problem. thanks again! ;)