|
11 | 11 | use ipl\Orm\Model;
|
12 | 12 | use ipl\Orm\Query;
|
13 | 13 | use ipl\Orm\Relations;
|
| 14 | +use ipl\Sql\Adapter\Pgsql; |
14 | 15 | use ipl\Sql\Connection;
|
15 | 16 | use ipl\Sql\Expression;
|
16 | 17 | use ipl\Sql\Select;
|
@@ -70,6 +71,7 @@ public function createBehaviors(Behaviors $behaviors): void
|
70 | 71 | {
|
71 | 72 | $behaviors->add(new Binary([
|
72 | 73 | 'id',
|
| 74 | + 'child_id', |
73 | 75 | 'host_id',
|
74 | 76 | 'service_id',
|
75 | 77 | 'redundancy_group_id'
|
@@ -115,15 +117,23 @@ public static function on(Connection $db, Model $root = null): Query
|
115 | 117 |
|
116 | 118 | private static function selectNodes(Connection $db, Model $root): Select
|
117 | 119 | {
|
| 120 | + if ($db->getAdapter() instanceof Pgsql) { |
| 121 | + $binaryCast = "CAST('00000000000000000000' AS bytea20)"; |
| 122 | + $booleanCast = "CAST('0' AS boolean)"; |
| 123 | + } else { |
| 124 | + $binaryCast = "CAST('' AS binary(20))"; |
| 125 | + $booleanCast = '0'; |
| 126 | + } |
| 127 | + |
118 | 128 | $rootQuery = DependencyNode::on($db)
|
119 | 129 | ->columns([
|
120 | 130 | 'id' => 'id',
|
121 | 131 | 'child_id' => 'id',
|
122 | 132 | 'level' => new Expression('0'),
|
123 | 133 | 'host_id' => 'host_id',
|
124 |
| - 'service_id' => new Expression("COALESCE(%s, CAST('' as binary(20)))", ['service_id']), |
125 |
| - 'redundancy_group_id' => new Expression("CAST('' as binary(20))"), |
126 |
| - 'is_group_member' => new Expression('0') |
| 134 | + 'service_id' => new Expression("COALESCE(%s, $binaryCast)", ['service_id']), |
| 135 | + 'redundancy_group_id' => new Expression($binaryCast), |
| 136 | + 'is_group_member' => new Expression($booleanCast) |
127 | 137 | ]);
|
128 | 138 | if ($root instanceof Host) {
|
129 | 139 | $rootQuery->filter(Filter::all(
|
|
0 commit comments