DragonByte Tech
Well-known member
- Affected version
- 2.1.0 Beta 2
The fact that you decided to impose this arbitrary limitation instead of creating a new method on
Consider the following scenario:
Let's say you have a Repository method,
Let's now say someone creates an add-on for my product, that adds a new database table and a new entity that relates to the License entity, so they add the relation via a class extension / event listener and they go to extend
You might think "you should just add this relation to the
Sure, I could copy-paste the
The solution should be quite simple:
You don't even have to make any changes to existing XF2 finder alias calls in order to support this feature for developers, so fixing this design flaw should not require re-testing every part of XF2 that currently uses finder aliases.
Fillip
\XF\Mvc\Entity\Finder
absolutely cripples extendability for Repositories. I consider it a bug because it's a design flaw that has an easy solution.Consider the following scenario:
Let's say you have a Repository method,
findLicensesByUser
. It normally includes the old forFullView
method, does some other stuff based on input, and returns the finder. Before, I would simply call $finder->forFullView()
and let method chaining take it from there. That won't work if I'm using aliases.Let's now say someone creates an add-on for my product, that adds a new database table and a new entity that relates to the License entity, so they add the relation via a class extension / event listener and they go to extend
findLicensesByUser
. Uh-oh, they can't add a new ->with()
call because aliases must be the last relations requested.You might think "you should just add this relation to the
withAliases
method that replaces forFullView instead" and sure, that works, if you need that relation at all times where forFullView
was normally used. But what if you don't? Why force developers to include a relation that may be a waste of time and resources?Sure, I could copy-paste the
->with('full')
everywhere directly below the ->fetch()
call, but that violates DRY (Don't Repeat Yourself).The solution should be quite simple:
- Add a new property,
protected $withAliases = [];
- Add a new method,
public function withAlias($name)
which appends to the$this->withAliases
property - Above
foreach ($this->joins AS $join)
or wherever else ingetQuery
you might deem relevant, loop through$this->withAliases
and add them to joins as they are just now
You don't even have to make any changes to existing XF2 finder alias calls in order to support this feature for developers, so fixing this design flaw should not require re-testing every part of XF2 that currently uses finder aliases.
Fillip