@@ -63,7 +63,7 @@ public function testApply(
63
63
*/
64
64
public function dataProviderApply (): array {
65
65
return [
66
- 'query builder not supported ' => [
66
+ 'query builder not supported ' => [
67
67
new SearchLogicException (sprintf (
68
68
'Operator `%s` can not be used with `%s`. ' ,
69
69
(new Relation ())->getName (),
@@ -75,61 +75,60 @@ static function (self $test): QueryBuilder {
75
75
'test ' ,
76
76
[],
77
77
],
78
- 'not a relation ' => [
78
+ 'not a relation ' => [
79
79
new LogicException (sprintf (
80
80
'Property `%s` is not a relation. ' ,
81
81
'delete ' ,
82
82
)),
83
83
static function (): EloquentBuilder {
84
- return RelationTest__Model ::query ();
84
+ return RelationTest__ModelA ::query ();
85
85
},
86
86
'delete ' ,
87
87
[],
88
88
],
89
- '{has: yes} ' => [
89
+ '{has: yes} ' => [
90
90
[
91
- 'sql ' => 'select * from "tmp " where exists ( ' .
92
- 'select * from "tmp" as "table_alias_0 " ' .
93
- 'where "tmp "."id" = "table_alias_0 "."relation_test___model_id " ' .
91
+ 'sql ' => 'select * from "table_a " where exists ( ' .
92
+ 'select * from "table_b " ' .
93
+ 'where "table_a "."id" = "table_b "."table_a_id " ' .
94
94
') ' ,
95
95
'bindings ' => [],
96
96
],
97
97
static function (): EloquentBuilder {
98
- return RelationTest__Model ::query ();
98
+ return RelationTest__ModelA ::query ();
99
99
},
100
100
'test ' ,
101
101
[
102
102
'has ' => 'yes ' ,
103
103
],
104
104
],
105
- '{has: yes, not: yes} ' => [
105
+ '{has: yes, not: yes} ' => [
106
106
[
107
- 'sql ' => 'select * from "tmp " where not exists ( ' .
108
- 'select * from "tmp" as "table_alias_0 " ' .
109
- 'where "tmp "."id" = "table_alias_0 "."relation_test___model_id " ' .
107
+ 'sql ' => 'select * from "table_a " where not exists ( ' .
108
+ 'select * from "table_b " ' .
109
+ 'where "table_a "."id" = "table_b "."table_a_id " ' .
110
110
') ' ,
111
111
'bindings ' => [],
112
112
],
113
113
static function (): EloquentBuilder {
114
- return RelationTest__Model ::query ();
114
+ return RelationTest__ModelA ::query ();
115
115
},
116
116
'test ' ,
117
117
[
118
118
'has ' => 'yes ' ,
119
119
'not ' => 'yes ' ,
120
120
],
121
121
],
122
- '{has: {property: {eq: 1}}} ' => [
122
+ '{has: {property: {eq: 1}}} ' => [
123
123
[
124
- 'sql ' => 'select * from "tmp" where exists ( ' .
125
- 'select * from "tmp" as "table_alias_0" where ' .
126
- '"tmp"."id" = "table_alias_0"."relation_test___model_id" ' .
127
- 'and "table_alias_0"."property" = ? ' .
124
+ 'sql ' => 'select * from "table_a" where exists ( ' .
125
+ 'select * from "table_b" where ' .
126
+ '"table_a"."id" = "table_b"."table_a_id" and "property" = ? ' .
128
127
') ' ,
129
128
'bindings ' => [123 ],
130
129
],
131
130
static function (): EloquentBuilder {
132
- return RelationTest__Model ::query ();
131
+ return RelationTest__ModelA ::query ();
133
132
},
134
133
'test ' ,
135
134
[
@@ -140,33 +139,33 @@ static function (): EloquentBuilder {
140
139
],
141
140
],
142
141
],
143
- '{has: yes, eq: 1} ' => [
142
+ '{has: yes, eq: 1} ' => [
144
143
[
145
- 'sql ' => 'select * from "tmp " where ( ' .
146
- 'select count(*) from "tmp" as "table_alias_0 " where ' .
147
- '"tmp "."id" = "table_alias_0 "."relation_test___model_id " ' .
144
+ 'sql ' => 'select * from "table_a " where ( ' .
145
+ 'select count(*) from "table_b " where ' .
146
+ '"table_a "."id" = "table_b "."table_a_id " ' .
148
147
') = 345 ' ,
149
148
'bindings ' => [/* strange */ ],
150
149
],
151
150
static function (): EloquentBuilder {
152
- return RelationTest__Model ::query ();
151
+ return RelationTest__ModelA ::query ();
153
152
},
154
153
'test ' ,
155
154
[
156
155
'has ' => 'yes ' ,
157
156
'eq ' => 345 ,
158
157
],
159
158
],
160
- '{has: yes, eq: 1, not: yes} ' => [
159
+ '{has: yes, eq: 1, not: yes} ' => [
161
160
[
162
- 'sql ' => 'select * from "tmp " where ( ' .
163
- 'select count(*) from "tmp" as "table_alias_0 " ' .
164
- 'where "tmp "."id" = "table_alias_0 "."relation_test___model_id " ' .
161
+ 'sql ' => 'select * from "table_a " where ( ' .
162
+ 'select count(*) from "table_b " ' .
163
+ 'where "table_a "."id" = "table_b "."table_a_id " ' .
165
164
') != 345 ' ,
166
165
'bindings ' => [/* strange */ ],
167
166
],
168
167
static function (): EloquentBuilder {
169
- return RelationTest__Model ::query ();
168
+ return RelationTest__ModelA ::query ();
170
169
},
171
170
'test ' ,
172
171
[
@@ -175,12 +174,12 @@ static function (): EloquentBuilder {
175
174
'eq ' => 345 ,
176
175
],
177
176
],
178
- '{has: yes, eq: 1, gt: 2} ' => [
177
+ '{has: yes, eq: 1, gt: 2} ' => [
179
178
new SearchLogicException (
180
179
'Only one comparison operator allowed, found: `eq`, `gt` ' ,
181
180
),
182
181
static function (): EloquentBuilder {
183
- return RelationTest__Model ::query ();
182
+ return RelationTest__ModelA ::query ();
184
183
},
185
184
'test ' ,
186
185
[
@@ -189,6 +188,27 @@ static function (): EloquentBuilder {
189
188
'gt ' => 2 ,
190
189
],
191
190
],
191
+ '{has: {property: {eq: 1}}} (own) ' => [
192
+ [
193
+ 'sql ' => 'select * from "table_a" where exists ( ' .
194
+ 'select * from "table_a" as "table_alias_0" where ' .
195
+ '"table_a"."id" = "table_alias_0"."relation_test___model_a_id" ' .
196
+ 'and "table_alias_0"."property" = ? ' .
197
+ ') ' ,
198
+ 'bindings ' => [123 ],
199
+ ],
200
+ static function (): EloquentBuilder {
201
+ return RelationTest__ModelA::query ();
202
+ },
203
+ 'a ' ,
204
+ [
205
+ 'has ' => [
206
+ 'property ' => [
207
+ 'eq ' => 123 ,
208
+ ],
209
+ ],
210
+ ],
211
+ ],
192
212
];
193
213
}
194
214
// </editor-fold>
@@ -201,15 +221,32 @@ static function (): EloquentBuilder {
201
221
* @internal
202
222
* @noinspection PhpMultipleClassesDeclarationsInOneFile
203
223
*/
204
- class RelationTest__Model extends Model {
224
+ class RelationTest__ModelA extends Model {
205
225
/**
206
226
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
207
227
*
208
228
* @var string
209
229
*/
210
- public $ table = 'tmp ' ;
230
+ public $ table = 'table_a ' ;
211
231
212
232
public function test (): HasOne {
233
+ return $ this ->hasOne (RelationTest__ModelB::class, 'table_a_id ' );
234
+ }
235
+
236
+ public function a (): HasOne {
213
237
return $ this ->hasOne (static ::class);
214
238
}
215
239
}
240
+
241
+ /**
242
+ * @internal
243
+ * @noinspection PhpMultipleClassesDeclarationsInOneFile
244
+ */
245
+ class RelationTest__ModelB extends Model {
246
+ /**
247
+ * @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
248
+ *
249
+ * @var string
250
+ */
251
+ public $ table = 'table_b ' ;
252
+ }
0 commit comments