Skip to content

Commit f8a4d17

Browse files
committed
#21 Use a less invasive querying approach
This is more suitable for a behavior context
1 parent 46c93e4 commit f8a4d17

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

database/behavior/taggable.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,21 @@ protected function _beforeSelect(KDatabaseContext $context)
5555
{
5656
$package = $this->getMixer()->getIdentifier()->package;
5757

58-
$query->join($package.'_tags_relations AS tags_relations', 'tags_relations.row = tbl.uuid');
59-
$query->join($package.'_tags AS tags', 'tags.tag_id = tags_relations.tag_id');
60-
$query->where('tags.slug IN :tag');
6158

62-
if ($this->getConfig()->strict) {
63-
$query->group('tbl.uuid')->having('COUNT(*) = :tag_count')->bind(array('tag_count' => count((array) $query->getParameters()->tag)));
59+
if ($this->getConfig()->strict)
60+
{
61+
$tags = KObjectConfig::unbox($this->getConfig()->tags);
62+
63+
for ($i = 0; $i < count($tags); $i++) {
64+
$query->join("{$package}_tags_relations AS tags_relations{$i}", "tags_relations{$i}.row = tbl.uuid")
65+
->join("{$package}_tags AS tags{$i}", "tags{$i}.tag_id = tags_relations{$i}.tag_id", 'INNER')
66+
->where("tags{$i}.slug = :tag{$i}")
67+
->bind(array("tag{$i}" => $tags[$i]));
68+
}
6469
}
70+
else $query->join($package . '_tags_relations AS tags_relations', 'tags_relations{$i}.row = tbl.uuid')
71+
->join($package . '_tags AS tags', 'tags.tag_id = tags_relations.tag_id')
72+
->where('tags.slug IN :tag');
6573
}
6674
}
6775
}

0 commit comments

Comments
 (0)