I have two models in Phalcon .I am getting the model object of the first model using the Placon Model::find()
. The problem is I cannot get model object which has an one to one relation with the first model.
I have tried everthing given in Phalcon tutorial.
Gave hasone in first Model on initialize
public function initialize()
{
$this->hasOne("emp_id", "Employee", "emp_id");
}
Where emp_id is the primary key of Employee table and Foreign key in Salary table, which is my second model.
For that you have to specify the relation between 2 models, and how those two models are related. To get one-to-one relation object you can use hasOne
relation or hasMany
for many-to-many relations.
$this->hasOne('emp_id', '(path to your model)', 'emp_id', array(
'alias' => 'employeeId',
'reusable' => true
));
Ex: if you have a Employee
object and you need access the one-to-one related objects you must use Employee.employeeId
to get the related object.