add column unique numbering scheme, more efficient selects
This commit is contained in:
+17
-1
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Tables\Column;
|
||||
use Illuminate\Support\Collection;
|
||||
use Riesjart\Relaquent\Model\Concerns\HasRelaquentRelationships;
|
||||
|
||||
@@ -32,7 +33,22 @@ class Revision extends BaseModel
|
||||
/** Included rows */
|
||||
public function rows()
|
||||
{
|
||||
return $this->belongsToMany(Row::class, 'revision_row_pivot');
|
||||
return $this->belongsToMany(Row::class, 'revision_row_pivot')->as('_row_pivot');
|
||||
}
|
||||
|
||||
/** Included rows
|
||||
* @param Column[] $columns
|
||||
* @return \Illuminate\Database\Query\Builder|static
|
||||
*/
|
||||
public function rowsData($columns, $withId=true)
|
||||
{
|
||||
$selects = $withId ? ["data->>'_id' as _id"] : [];
|
||||
|
||||
foreach ($columns as $col) {
|
||||
$selects[] = "data->>'$col->id' as $col->name";
|
||||
}
|
||||
|
||||
return $this->rows()->select([])->selectRaw(implode(', ', $selects));
|
||||
}
|
||||
|
||||
/** Proposal that lead to this revision */
|
||||
|
||||
Reference in New Issue
Block a user