Level 74
What does the SQL look like?
$query->toSql();
Greetings,
I hope someone can help me. I am having an issue with duplicate records being included in my search while doing several joins and using pagination. Here is my query:
$query = Property::query();
$query->join('calcs', 'properties.id', '=', 'calcs.property_id')->whereHas('calcs');
$query->leftJoin('transactions', 'properties.id', '=', 'transactions.property_id');
$query->leftJoin('offers', 'properties.id', '=', 'offers.property_id');
$query->select('properties.*', 'calcs.*', 'transactions.sale_date', 'offers.status', 'offers.id');
$query->distinct();
$query->orderByRaw('calcs.flip_score DESC NULLS LAST');
$query->paginate($paginate);
I also have this on my property object:
return DB::SELECT('SELECT ST_X(location::geometry) as longitude,ST_Y(location::geometry) as latitude FROM properties WHERE id = ?', [$this->id]);
/**
* This method dynamically adds latitude and longitude to App\Property object
*/
public function newQuery()
{
return parent::newQuery()->select('properties.*', \DB::raw('ST_X(location::geometry) as longitude,ST_Y(location::geometry) as latitude'));
}
Please or to participate in this conversation.