Skip to content

Commit

Permalink
Added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oojacoboo committed Sep 11, 2023
1 parent 25b2a54 commit 30dc83b
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ use Rentpost\Doctrine\MultiTenancy\Attribute\MultiTenancy;
#[MultiTenancy(filters: [
new MuiltiTenancy\Filter(where: '$this.company_id = {companyId}'),
new MultiTenancy\Filter(
context: ['manager'],
context: ['visitor'],
where: '$this.id IN(
SELECT product_id
FROM product_group
Expand All @@ -170,6 +170,43 @@ class Product
}
```

#### Example with multiple context filters and a strategy

In the previous examples, we've been using the default `FilterStrategy::AnyMatch`, which means that
any of the contexts that evaluate as true have had their where clause applied. In this example, you
can see that we've applied a `FilterStrategy::FirstMatch`, which means the filter contextual filter
will be applied - only.

**Keep in mind, if you do not provide a context, it's assumed to be in context, and that filter will
be applied, meaning any subsequent filters will never be evaluated.**

```php
use Doctrine\ORM\Mapping as ORM;
use Rentpost\Doctrine\MultiTenancy\Attribute\MultiTenancy;

#[ORM\Entity]
#[MultiTenancy(
strategy: MultiTenancy\FilterStrategy::FirstMatch,
filters: [
new MuiltiTenancy\Filter(
context: ['admin']
where: '$this.company_id = {companyId}'),
new MultiTenancy\Filter(
context: ['visitor'],
where: '$this.id IN(
SELECT product_id
FROM product_group
WHERE status = 'published'
)'
),
],
)]
class Product
{
// Whatever
}
```

## Issues / Bugs / Questions

Please feel free to raise an issue against this repository if you have any questions or problems.
Expand Down

0 comments on commit 30dc83b

Please sign in to comment.