Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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');
    }
 
}
 

Last updated 2 years ago.
0

Maybe you should take a look at polymorphic relationships? http://laravel.com/docs/eloquent#many-to-many-polymorphic-relations

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.