@@ -217,11 +217,18 @@ public function validator($rule, $options = null, bool $clear = false): Field
217217 /**
218218 * @param string $class
219219 * @param string $target
220+ * @param string $name (null)
220221 * @return Field
221222 */
222- public function referencedBy (string $ class , string $ target ): Field
223+ public function referencedBy (string $ class , string $ target, string $ name = null ): Field
223224 {
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+ ];
225232 return $ this ;
226233 }
227234
@@ -230,16 +237,21 @@ public function referencedBy(string $class, string $target): Field
230237 *
231238 * @param string $class
232239 * @param string $referenced
233- * @param bool $nullable
240+ * @param bool $nullable (false)
241+ * @param string $name (null)
234242 * @return Field
235243 * @throws SimplesRunTimeError
236244 */
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
238246 {
239247 if (off ($ this ->references , 'class ' )) {
240248 throw new SimplesRunTimeError ("Relationship already defined to ' {$ this ->references ->class }' " );
241249 }
250+ if (!$ name ) {
251+ $ name = get_class_short_name ($ class );
252+ }
242253 $ this ->references = (object )[
254+ 'name ' => $ name ,
243255 'collection ' => $ this ->getCollection (),
244256 'referenced ' => $ referenced ,
245257 'class ' => $ class
0 commit comments