# |
Feb 19th 2020, 23:24 |
wizardfix |
How so? :thinking_face: |
# |
Feb 19th 2020, 23:24 |
ndm |
You'd need to swap that, the config must be set before doing the `paginate()` call... however you can also just call `contain()` and `limit()` on the query directly. |
# |
Feb 19th 2020, 23:23 |
wizardfix |
```public function index() { $users = $this->paginate($this->Users ->find() ->where(['status <' => 2])); $this->paginate = [ 'contain' => ['Creators'], 'limit' => 30 ]; debug($users); $this->set(compact('users')); }``` |
# |
Feb 19th 2020, 23:22 |
wizardfix |
```$this->paginate = [ 'contain' => ['Creators'], 'limit' => 30 ];``` in my view function |
# |
Feb 19th 2020, 23:22 |
ndm |
There is no creator... do you actually contain the association? |
# |
Feb 19th 2020, 23:21 |
slackebot |
false }, '[new]' => false, '[accessible]' => [ 'name' => true, 'email' => true, 'admin' => true, 'password' => true, 'status' => true, 'created_by' => true, 'created_on' => true ], '[dirty]' => [], '[original]' => [], '[virtual]' => [], '[hasErrors]' => false, '[errors]' => [], '[invalid]' => [], '[repository]' => 'Users' },``` A user from the list |
# |
Feb 19th 2020, 23:21 |
wizardfix |
```(int) 3 => object(App\Model\Entity\User) { 'id' => (int) 5, 'name' => 'Zaphod Beeblebrox', 'email' => 'infinite@galactic.net', 'admin' => false, 'password' => '$2y$10$M1IptedUMTnzyuolZF4uVOsSadqIoPn9kh8LHN7UXQC/0Z7WbYfvu', 'status' => (int) 1, 'created_by' => (int) 2, 'created_on' => object(Cake\I18n\FrozenTime) { 'time' => '2020-01-20 18:06:00.000000+00:00', 'timezone' => 'UTC', 'fixedNowTime' => |
# |
Feb 19th 2020, 23:20 |
wizardfix |
No, I just want to display theuser's name instead of the id. You showed me how to do this a couple of days ago when I was creating an association to a *different* table, but this time it doesn't seem to work the same- the default alias would cause a clash - `user` vs. `user`. |
# |
Feb 19th 2020, 23:20 |
ndm |
That would be a good starting point |
# |
Feb 19th 2020, 23:20 |
ndm |
I'd suggest that you do a `debug($users)` or `debug($users->toArray())` depending on what exactly `$users` is, to see what exactly is being set when you do not explicitly set a property name. |
# |
Feb 19th 2020, 23:18 |
ndm |
I don't really know what you're trying to do there... if you want to dispatch additional queries from your template then I would highly discourage from doing that. |
# |
Feb 19th 2020, 23:17 |
wizardfix |
I tried to do just `$users->get($user->created_by) in my template, but Cake told me `get()` is not defined. Perhaps there's a way to import get()? |
# |
Feb 19th 2020, 23:13 |
ndm |
Not too much I think... I'm not sure if it possible to create maybe a circular reference or some other kind of endless loop. |
# |
Feb 19th 2020, 23:12 |
wizardfix |
Is there something to be aware of when setting an association from a table to itself? |
# |
Feb 19th 2020, 23:12 |
ndm |
or just debug your whole query results to see what you get |
# |
Feb 19th 2020, 23:11 |
wizardfix |
Yes every row has a value for that column |
# |
Feb 19th 2020, 23:10 |
ndm |
But does every row have a value for that column? Also if you check `getProperty()` on your association, what does it return? |
# |
Feb 19th 2020, 23:09 |
ndm |
*inflection |
# |
Feb 19th 2020, 23:09 |
wizardfix |
Every user has a `created_by` field that is a foreign key refencing the same table |
# |
Feb 19th 2020, 23:09 |
ndm |
I don't know why `setPropertyName()` would change anything, as for `belongsTo`, `Creators` would by default translate to `creator` as property name... unless injection doesn't work properly. |
# |
Feb 19th 2020, 23:08 |
ndm |
That could for example mean that for that specific user there is no creator. |
# |
Feb 19th 2020, 23:07 |
slackebot |
Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65 Cake\Routing\Middleware\AssetMiddleware::__invoke() - CORE/src/Routing/Middleware/AssetMiddleware.php, line 88``` from referencing `$user->creator->name` |
# |
Feb 19th 2020, 23:07 |
slackebot |
line 65 Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65 Cake\Http\Middleware\CsrfProtectionMiddleware::__invoke() - CORE/src/Http/Middleware/CsrfProtectionMiddleware.php, line 124 Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65 Cake\Http\Runner::run() - CORE/src/Http/Runner.php, line 51 Cake\Routing\Middleware\RoutingMiddleware::__invoke() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 168 |
# |
Feb 19th 2020, 23:07 |
slackebot |
Cake\View\View::render() - CORE/src/View/View.php, line 879 Cake\Controller\Controller::render() - CORE/src/Controller/Controller.php, line 795 Cake\Http\ActionDispatcher::_invoke() - CORE/src/Http/ActionDispatcher.php, line 126 Cake\Http\ActionDispatcher::dispatch() - CORE/src/Http/ActionDispatcher.php, line 94 Cake\Http\BaseApplication::__invoke() - CORE/src/Http/BaseApplication.php, line 234 Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, |
# |
Feb 19th 2020, 23:07 |
wizardfix |
If I leave out the `setPropertyName()` call I get ```Notice (8): Trying to get property 'name' of non-object [APP/Template/Users/index.ctp, line 43] Code Context Cake\Core\BasePlugin::{closure}() - ROOT/vendor/cakephp/debug_kit/config/bootstrap.php, line 42 include - APP/Template/Users/index.ctp, line 43 Cake\View\View::_evaluate() - CORE/src/View/View.php, line 1420 Cake\View\View::_render() - CORE/src/View/View.php, line 1381 |
# |
Feb 19th 2020, 23:06 |
ndm |
I doubt that calling `setPropertyName()` is resposible though |
# |
Feb 19th 2020, 23:05 |
ndm |
Well, there's a memory leak somewhere, but it's impossible for me to tell where it is, you need some better debugging tools ;) |
# |
Feb 19th 2020, 23:05 |
wizardfix |
If I logout and login again I get ```Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) in /opt/lampp/htdocs/trportal/vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php on line 276 Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0``` |
# |
Feb 19th 2020, 23:04 |
wizardfix |
Just the standard cake debugging system |
# |
Feb 19th 2020, 23:03 |
ndm |
I mean, the property name should by default be `creator`, shouldn't it? Anyhow... is there a stacktrace for that? (which basically means to do you have xdebug installed/enabled?) |
# |
Feb 19th 2020, 22:59 |
wizardfix |
Line 466 in Association.php is `$this->_targetTable = $tableLocator->get($registryAlias, $config);` and line 126 of Configure.php is the return statement of this function: ```public static function read($var = null, $default = null) { if ($var === null) { return static::$_values; } return Hash::get(static::$_values, $var, $default); }``` |
# |
Feb 19th 2020, 22:55 |
slackebot |
536870912 bytes exhausted (tried to allocate 262144 bytes) in /opt/lampp/htdocs/trportal/vendor/cakephp/cakephp/src/ORM/Association.php on line 466 Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) in /opt/lampp/htdocs/trportal/vendor/cakephp/cakephp/src/Core/Configure.php on line 126``` Is this a bug in Cake or have I just got the syntax wrong? :thinking_face: |
# |
Feb 19th 2020, 22:55 |
wizardfix |
(3.8) Hmmm... Trying to set an association in my `UsersTable`: each `User` has a `created_by` field, which is a foreign key that self-references the `UsersTable.` `I have` ```$this->belongsTo('Creators') ->setClassName('Users') ->setForeignKey('created_by');``` but every time I add `->setPropertyName('creator');` to this, so I can reference `$user->creator->name` in my view, I get ``` Fatal error: Allowed memory size of |
# |
Feb 19th 2020, 22:54 |
ricksaccous |
anyway, thanks, cheers |
# |
Feb 19th 2020, 22:50 |
ricksaccous |
so whatever i do in my appController is for naught in that case |
# |
Feb 19th 2020, 22:49 |
ricksaccous |
yeah it's prob the less hacky way anyway, i suppose that the plugin calls parent::beforeRender after it sets the layouts and that's what's causing this, I believe it inherits my appController |
# |
Feb 19th 2020, 22:47 |
ndm |
Generally there's nothing wrong with overriding plugin templates. Depending on the template you might be able to extend it and add your css. |
# |
Feb 19th 2020, 22:46 |
ricksaccous |
even though it's gross |
# |
Feb 19th 2020, 22:45 |
ricksaccous |
that seems to be working... |
# |
Feb 19th 2020, 22:43 |
ricksaccous |
but i might just do it by over-riding all templates and see if that works |
# |
Feb 19th 2020, 22:43 |
ricksaccous |
to the layout |