Skip to content

Commit 7d48abd

Browse files
authored
Apply whereRaw and updated_at
Retrieving the projection also requires a whereRaw to handle the backslashes in the projection_name. The updated_at field should be used to determine the start_date as not the created_at.
1 parent b0f29b2 commit 7d48abd

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/Projector.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,28 @@ private function parsePeriod(string $period): void
8787
*/
8888
private function findGlobalProjection(): Projection|null
8989
{
90-
return Projection::firstWhere([
91-
['projection_name', $this->projectionName],
92-
['key', $this->hasKey() ? $this->key() : null],
93-
['period', '*'],
94-
['start_date', null],
95-
]);
90+
return Projection::whereRaw('projection_name = ?', [$this->projectionName])
91+
->where([
92+
['key', $this->hasKey() ? $this->key() : null],
93+
['period', '*'],
94+
['start_date', null],
95+
])
96+
->first();
9697
}
9798

9899
/**
99100
* Finds the projection if it exists.
100101
*/
101102
private function findProjection(string $period): Projection|null
102103
{
103-
return Projection::firstWhere([
104-
['projection_name', $this->projectionName],
105-
['key', $this->hasKey() ? $this->key() : null],
106-
['period', $period],
107-
['start_date', app(TimeSeries::class)->resolveFloorDate($this->projectedModel->created_at, $period)],
108-
]);
104+
return Projection::whereRaw('projection_name = ?', [$this->projectionName])
105+
->where([
106+
['key', $this->hasKey() ? $this->key() : null],
107+
['period', $period],
108+
['start_date', app(TimeSeries::class)->resolveFloorDate($this->projectedModel->updated_at, $period),
109+
],
110+
])
111+
->first();
109112
}
110113

111114
/**
@@ -117,7 +120,7 @@ private function createProjection(string $period): void
117120
'projection_name' => $this->projectionName,
118121
'key' => $this->hasKey() ? $this->key() : null,
119122
'period' => $period,
120-
'start_date' => app(TimeSeries::class)->resolveFloorDate($this->projectedModel->created_at, $period),
123+
'start_date' => app(TimeSeries::class)->resolveFloorDate($this->projectedModel->updated_at, $period),
121124
'content' => $this->mergeProjectedContent((new $this->projectionName())->defaultContent(), $period),
122125
]);
123126
}

0 commit comments

Comments
 (0)