@@ -68,11 +68,12 @@ public function __construct( array $attributes = [] ) {
6868 * @since 2.0.0 changed to static
6969 *
7070 * @param string $type
71- * @param mixed $value
71+ * @param mixed $value The query data value to cast, probably a string.
72+ * @param string $property The property being casted.
7273 *
7374 * @return mixed
7475 */
75- protected static function castValueForProperty ( string $ type , $ value ) {
76+ protected static function castValueForProperty ( string $ type , $ value, string $ property ) {
7677 switch ( $ type ) {
7778 case 'int ' :
7879 return (int ) $ value ;
@@ -390,7 +391,7 @@ public function jsonSerialize() {
390391 * Constructs a model instance from database query data.
391392 *
392393 * @param object|array $queryData
393- * @param int $mode The level of strictness to take when constructing the object
394+ * @param int $mode The level of strictness to take when constructing the object, by default it will ignore extra keys but error on missing keys.
394395 * @return static
395396 */
396397 public static function fromQueryData ($ queryData , $ mode = self ::BUILD_MODE_IGNORE_EXTRA ): static {
@@ -423,7 +424,7 @@ public static function fromQueryData($queryData, $mode = self::BUILD_MODE_IGNORE
423424 }
424425
425426 // Remember not to use $type, as it may be an array that includes the default value. Safer to use getPropertyType().
426- $ instance ->setAttribute ($ key , static ::castValueForProperty (static ::getPropertyType ($ key ), $ queryData [$ key ]));
427+ $ instance ->setAttribute ($ key , static ::castValueForProperty (static ::getPropertyType ($ key ), $ queryData [$ key ], $ key ));
427428 }
428429
429430 return $ instance ;
0 commit comments