we cannot use two field relationship with (one to one) ,
I solved this ,
return HouseHold::where("printedcardno","=","17130103-0124")->with(array('members' => function($query)
{
$query->leftJoin('PatientCard', function($join)
{
$join->on('PatientCard.HouseHoldID', '=', 'shp_members.HouseHoldID')
->on('PatientCard.MemberID', '=', 'shp_members.MemberID');
});
}))->get()->take(10)->toArray();
// HouseHold model
<?php
class HouseHold extends Eloquent {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'shp_households';
/**
* Defines a one-to-many relationship.
*
* @see http://laravel.com/docs/eloquent#one-to-many
*/
public function members()
{
return $this->hasMany('Member', 'HouseHoldID','HouseHoldID');
}
}
Maybe you should take a look at polymorphic relationships? http://laravel.com/docs/eloquent#many-to-many-polymorphic-relations
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community