public static function getModelKeys($model, $includePrimary = true)
    {
        $keys = array_map(function ($foreignKey) {
            array_shift($foreignKey);
            return array_keys($foreignKey);
        }, $model->getTableSchema()->foreignKeys);
        if ($includePrimary) {
            $keys[] = $model->primaryKey();
        }
        return call_user_func_array('array_merge', $keys);
    }