@@ -217,11 +217,18 @@ public function validator($rule, $options = null, bool $clear = false): Field
217
217
/**
218
218
* @param string $class
219
219
* @param string $target
220
+ * @param string $name (null)
220
221
* @return Field
221
222
*/
222
- public function referencedBy (string $ class , string $ target ): Field
223
+ public function referencedBy (string $ class , string $ target, string $ name = null ): Field
223
224
{
224
- $ this ->referenced [$ target ] = $ class ;
225
+ if (!$ name ) {
226
+ $ name = get_class_short_name ($ class );
227
+ }
228
+ $ this ->referenced [$ target ] = [
229
+ 'name ' => $ name ,
230
+ 'class ' => $ class
231
+ ];
225
232
return $ this ;
226
233
}
227
234
@@ -230,16 +237,21 @@ public function referencedBy(string $class, string $target): Field
230
237
*
231
238
* @param string $class
232
239
* @param string $referenced
233
- * @param bool $nullable
240
+ * @param bool $nullable (false)
241
+ * @param string $name (null)
234
242
* @return Field
235
243
* @throws SimplesRunTimeError
236
244
*/
237
- public function referencesTo (string $ class , string $ referenced , bool $ nullable = false ): Field
245
+ public function referencesTo (string $ class , string $ referenced , bool $ nullable = false , string $ name = null ): Field
238
246
{
239
247
if (off ($ this ->references , 'class ' )) {
240
248
throw new SimplesRunTimeError ("Relationship already defined to ' {$ this ->references ->class }' " );
241
249
}
250
+ if (!$ name ) {
251
+ $ name = get_class_short_name ($ class );
252
+ }
242
253
$ this ->references = (object )[
254
+ 'name ' => $ name ,
243
255
'collection ' => $ this ->getCollection (),
244
256
'referenced ' => $ referenced ,
245
257
'class ' => $ class
0 commit comments