hello trying access value joined table schead.section store in subjectcontainer.section, using scstock data section part located in schead.section did join schead , schstock can have access section column. here did.
$subject = activecurriculum::find() ->select('scstock.*') ->leftjoin('schead', 'schead.trno = scstock.trno') ->where([ 'schead.trno' => $trno]) ->one(); $activesubject = new activesubject(); $activesubject->clientid = $clientid; $activesubject->trno = $subject->trno; $activesubject->subjectcode = $subject->subjectcode; $activesubject->schedday = $subject->schedday; $activesubject->schedtime = $subject->schedtime; $activesubject->section = $subject->section; $activesubject->room = $subject->room; $activesubject->units = $subject->units; $activesubject->save(); //reduces slot of ccsubject 1 $subject->slots = $subject->slots - 1; //never forget saving part $subject->save();
first $subject
access sctock table join schead via trno. $activesubject
access subjectcontainer table store values in. problem getting error.
can me in trying solve this?
make sure define relation schead
object in model. example of such relation:
/** * @property $schead schead */ class yourmodel extends \yii\db\activerecord { /** * @return schead */ public function getschead() { return $this->hasone(schead::classname(), ['field1' => 'field2']); } }
also, $subject->schead.section
wrong way of accessing related model attributes. use $subject->schead->section
instead. if having schead optional, don't forget check existence of related object first, example:
$subject->schead ? $subject->schead->section : null
also check code typos (probably sched
/ schead
?). can read more working relations in official docs.
Comments
Post a Comment