FareedR
3 months ago
270
1
Laravel

Cannot retrieve other field

Posted 3 months ago by FareedR

How can I get "signal" in my query? I already put 'signal' in select method. i get an error "SELECT list is not in GROUP BY clause and contains nonaggregated.... " . I reuse my previous method code, everything works.

// database 
id | stock_id | signal 
1          1              ABCD
2          1              EFGH

// query
 $stocks = Stock::with(['signals' => function ($query){
	$query->select(['stock_id'])->groupBy('stock_id');
}])->get();

Please sign in or create an account to participate in this conversation.