public static function reverseForeignKey(
        string $model_class,
        Model $target
    ) {
        $target_class = get_class($target);

        $column = null;
        $found = false;
        foreach ($model_class::FOREIGN_KEYS as $column => $fk) {
            if ($target_class === $fk[0]) {
                $found = true;
                break;
            }
        }
        if ($column === null || $found === false) {
            return;
        }

        return [$column => $target->__get($fk[1])];
    }
public static function reverseForeignKey(
        string $model_class,
        Model $target
    ) {
        $target_class = get_class($target);

        $column = null;
        $found = false;
        foreach ($model_class::FOREIGN_KEYS as $column => $fk) {
            if ($target_class === $fk[0]) {
                $found = true;
                break;
            }
        }
        if ($column === null || $found === false) {
            return;
        }

        return [$column => $target->__get($fk[1])];
    }
public static function reverseForeignKey ( string $ model_class , Model $ target ) { $ target_class = get_class ( $ target ) ; $ column = null ; $ found = false ; foreach ( $ model_class :: FOREIGN_KEYS as $ column => $ fk ) { if ( $ target_class === $ fk [ 0 ] ) { $ found = true ; break ; } } if ( $ column === null || $ found === false ) { return ; } return [ $ column => $ target -> __get ( $ fk [ 1 ] ) ] ; }
Finds the Foreign Key for a Model instance from a Model class

NOTE:
- If $model_class has multiple foreign keys for $target, only the first
one is used. You should redesign your database, duplicate the target
class with a new name or create a new class that extends target, if you
want to match later $model_class foreign keys

@param string $model_class Model with Foreign Key pointing to $target
@param Model  $target      Model pointed by $model_class

@return mixed[] \Medoo\Medoo $where clause for $target, using a Foreign
Key in $model_class
@return null    On failure
Finds the Foreign Key for a Model instance from a Model class