Skip to content

Commit d63d580

Browse files
committed
added case for 1:0 relation with the table itself
1 parent 6b965aa commit d63d580

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Model/Service/SqlService.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,28 @@ public function get($key, $id)
168168
//get 1:0 relations
169169
$relations = $this->schema->getRelations(0);
170170
foreach ($relations as $table => $relation) {
171+
$schema = $this->schema;
172+
171173
$row = $this
172174
->resource
173175
->search($table)
174-
->innerJoinUsing($relation['name'], $relation['primary2'])
176+
->when(
177+
//we need to case for post_post for example
178+
$relation['name'] === $this->schema->getName(),
179+
//this is the post_post way
180+
function () use (&$schema, &$relation) {
181+
$on = sprintf(
182+
'%s = %s',
183+
$schema->getPrimaryFieldName(),
184+
$relation['primary2']
185+
);
186+
$this->innerJoinOn($relation['name'], $on);
187+
},
188+
//this is the normal way
189+
function () use (&$relation, &$fields) {
190+
$this->innerJoinUsing($relation['name'], $relation['primary2']);
191+
}
192+
)
175193
->addFilter($relation['primary1'] . ' = %s', $id)
176194
->getRow();
177195

0 commit comments

Comments
 (0)