# |
Aug 13th 2019, 10:04 |
neon1024 |
It got refactored a while ago to try and remove the static interface |
# |
Aug 13th 2019, 10:04 |
vossen.steven |
Yea was just thinking getTableLocator probly uses the same obj |
# |
Aug 13th 2019, 10:04 |
neon1024 |
@challgren Well that method will be pulling the instance from the registry if one already exists |
# |
Aug 13th 2019, 10:03 |
challgren |
Doesn’t make sense to make a new object when sometimes I use getTableLocator() multiple times |
# |
Aug 13th 2019, 10:02 |
neon1024 |
@val Good luck! 8) |
# |
Aug 13th 2019, 10:02 |
challgren |
IDK honestly, I always coded `TableRegistry::getTableLocator()->get()` well `TableRegistry::get()` |
# |
Aug 13th 2019, 10:02 |
racmiroslav |
there is. `TableRegistry::getTableLocator()` is Singleton |
# |
Aug 13th 2019, 10:00 |
vossen.steven |
@challgren maybe a dumb question but is there a difference between `TableRegistry::getTableLocator()->get('Table')` and `(new TableLocator())->get('Table')` ? |
# |
Aug 13th 2019, 09:57 |
val |
@neon1024 nope, that's not what I asked. In 2.x there is an option to set table alias in data source object. It seems such option is missing in 3.x |
# |
Aug 13th 2019, 09:56 |
jotpe |
But skipAuthorization() has no parameter for actions. So how can i allow an action from one Controller? |
# |
Aug 13th 2019, 09:55 |
jotpe |
As mentioned over here Authorization can skipped for actions: https://book.cakephp.org/authorization/1.1/en/component.html#automatic-authorization-checks |
# |
Aug 13th 2019, 09:50 |
challgren |
Ahhh, how many assertions so far? |
# |
Aug 13th 2019, 09:50 |
neothermic |
@challgren also I've had to do other work inbetween writing tests :S |
# |
Aug 13th 2019, 09:49 |
neon1024 |
https://github.com/cakephp/cakephp/blob/master/src/Core/ObjectRegistry.php |
# |
Aug 13th 2019, 09:49 |
neon1024 |
@val Have a look at the ObjectRegistry class if you’re interested, it’s one of the key patterns for the whole framework, even in Cake 2 |
# |
Aug 13th 2019, 09:48 |
challgren |
@val maybe someone else knows a better answer, I by no means am a ORM expert |
# |
Aug 13th 2019, 09:48 |
neon1024 |
@val That’s exactly what you asked for |
# |
Aug 13th 2019, 09:47 |
neothermic |
it gets fun when you have a function with an npath of 442.. :) |
# |
Aug 13th 2019, 09:46 |
val |
omg. new table instance for each subquery?! that's insane |
# |
Aug 13th 2019, 09:45 |
neon1024 |
It can lead to sub-standard test-cases |
# |
Aug 13th 2019, 09:45 |
neon1024 |
Chasing coverage is dangerous |
# |
Aug 13th 2019, 09:44 |
challgren |
I had 100% at one time but it dropped to 80% and Im sad about it, but need to focus on getting it back up to 100% |
# |
Aug 13th 2019, 09:43 |
neon1024 |
So you can use it later again if needed |
# |
Aug 13th 2019, 09:43 |
neon1024 |
..and you’ll have added an alias to the Registry |
# |
Aug 13th 2019, 09:43 |
neon1024 |
Then you can use the return @val |
# |
Aug 13th 2019, 09:43 |
challgren |
Yes so you use $Example2->find() as your subquery |
# |
Aug 13th 2019, 09:43 |
neothermic |
@challgren unit tests. Working from critical parts forward |
# |
Aug 13th 2019, 09:43 |
slackebot1 |
<neon1024> |
# |
Aug 13th 2019, 09:43 |
challgren |
Are you just doing integration tests? |
# |
Aug 13th 2019, 09:42 |
val |
@challgren the same problem. I need the alias to be applied only to a single subquery. |
# |
Aug 13th 2019, 09:42 |
neon1024 |
Probably something like `$t = new TableLocator(); $t->get(‘Cat’, [ ‘className’ => \App\Model\Table\DogsTable::class ])` |
# |
Aug 13th 2019, 09:42 |
neothermic |
0.9% of 500k is still a lot of lines tested |
# |
Aug 13th 2019, 09:42 |
challgren |
Damm figured you’d be at least 5% |
# |
Aug 13th 2019, 09:41 |
neothermic |
argh, 0.9% covered. gotta keep going to hit that first 1% |
# |
Aug 13th 2019, 09:41 |
challgren |
`$Example2 = TableRegistry::getTableLocator()->get('Example')->setAlias('Example2');` |
# |
Aug 13th 2019, 09:41 |
neon1024 |
So I guess you’d need to load a new aliased instance |
# |
Aug 13th 2019, 09:40 |
neon1024 |
Although as Cake uses the Registry pattern you’ll always be changing the same instance, unless you clone it as @challgren said |
# |
Aug 13th 2019, 09:40 |
neon1024 |
`$query->getRepository()->setAlias();` |
# |
Aug 13th 2019, 09:39 |
challgren |
Yep not defined. |
# |
Aug 13th 2019, 09:39 |
val |
I can't find `setAlias` in Query class |
# |
Aug 13th 2019, 09:39 |
neon1024 |
Call it on the query instance instead of the table? |