Skip to content

Commit

Permalink
Added getQualifiedTenant() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Fidecaro committed Nov 29, 2016
1 parent cf3a456 commit 4828c32
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [v2.0.4] - 2016-11-30
### Added
- Added `getQualifiedTenant()` method to `BelongsToTenants` trait. Override this if you need to change or remove the qualification for a particular model, for example if you are using a NoSQL database.

## [v2.0.3] - 2016-11-30
### Changed
- Fixed Lumen compatibility by checking for presence of `config_path()` before trying to register publishable assets.
Expand Down
13 changes: 13 additions & 0 deletions src/BelongsToTenants.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ public function getTenantColumns()
return isset($this->tenantColumns) ? $this->tenantColumns : config('landlord.default_tenant_columns');
}

/**
* Returns the qualified tenant (table.tenant). Override this if you need to
* provide unqualified tenants, for example if you're using a noSQL Database.
*
* @param mixed $tenant
*
* @return mixed
*/
public function getQualifiedTenant($tenant)
{
return $this->getTable().'.'.$tenant;
}

/**
* Returns a new query builder without any of the tenant scopes applied.
*
Expand Down
4 changes: 2 additions & 2 deletions src/TenantManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getTenantId($tenant)
/**
* Applies applicable tenant scopes to a model.
*
* @param Model $model
* @param Model|BelongsToTenants $model
*/
public function applyTenantScopes(Model $model)
{
Expand All @@ -123,7 +123,7 @@ public function applyTenantScopes(Model $model)

$this->modelTenants($model)->each(function ($id, $tenant) use ($model) {
$model->addGlobalScope($tenant, function (Builder $builder) use ($tenant, $id, $model) {
$builder->where($model->getTable().'.'.$tenant, '=', $id);
$builder->where($model->getQualifiedTenant($tenant), '=', $id);
});
});
}
Expand Down

0 comments on commit 4828c32

Please sign in to comment.