As @Izo said, 1 model = 1 database table. Some time ago I had almost identical situation like you. Here is how I solved the problem back then. If someone else has better solution please share! :)
// Controller code
$form = new \Frontend\Forms\ProfileEdit($obj->getEditInfo());
// Model code (or whatever)
public function getEditInfo()
{
return $this->modelsManager->createBuilder()
->columns([
'profile.id',
'profile.names',
'profile.email',
'details.phone',
])
->from(['profile' => 'Models\Profiles'])
->leftJoin('Models\ProfileDetails', 'details.profile_id = profile.id', 'details')
->where('profile.id = :id:', ['id' => $this->id])
->getQuery()->getSingleResult();
}
Basically you have to use the Query Builder to create a single object and pass it as form entity in order to populate all the fields :)
UPDATE: Just in case someone asks: But how do I update the two models (database tables) after form is submitted and valited?
// Controller code
$form = new \Frontend\Forms\ProfileEdit($obj->getEditInfo());
if ($this->request->isPost() AND $this->security->checkToken() AND $form->isValid($this->request->getPost())) {
$obj->updateProfile($id, $this->request);
}
// Model code (or whatever)
function updateProfile($id, $request)
{
// Profiles table
$profile = Profiles::findFirst($id);
$profile->name = $request->getPost('names', 'striptags');
$profile->email = $request->getPost('email', 'email');
// Profile details table
$details = ProfileDetails::findFirstByProfileId($id);
$details->phone = $request->getPost('phone');;
// Try to save and return model errors if any
if ($profile->save() AND $details->save()) {
return [];
} else {
return array_merge((array) $profile->getMessages(), (array) $details->getMessages());
}
}