# |
Jul 16th 2021, 08:33 |
paolo.bragagni |
it was enough to know that |
# |
Jul 16th 2021, 08:33 |
paolo.bragagni |
wow |
# |
Jul 16th 2021, 08:32 |
joelmontefer13 |
$query = $this->Categorie ->find('search', ['search' => $this->request->getQueryParams()]) ->notMatching($return['returnmodel'], function ($q) use ($return) { return $q->where([$return['returnmodel'] . '.id' => $return['returncontrollerid']]); }); |
# |
Jul 16th 2021, 08:31 |
paolo.bragagni |
Imean, I'd like to pass a parameter inside the function |
# |
Jul 16th 2021, 08:29 |
paolo.bragagni |
$query = $this->Categorie ->find('search', ['search' => $this->request->getQueryParams()]) ->notMatching($return['returnmodel'], function ($q) { return $q->where([$return['returnmodel'] . '.id' => $return['returncontrollerid']]); }); |
# |
Jul 16th 2021, 08:29 |
paolo.bragagni |
how to do this? |
# |
Jul 16th 2021, 08:29 |
paolo.bragagni |
morning |
# |
Jul 15th 2021, 22:45 |
jh |
```$articles->Comments->getTable()``` |
# |
Jul 15th 2021, 22:44 |
jh |
https://api.cakephp.org/4.2/class-Cake.ORM.Table.html#getTable() |
# |
Jul 15th 2021, 22:42 |
jh |
https://book.cakephp.org/4/en/orm/table-objects.html |
# |
Jul 15th 2021, 22:42 |
jh |
https://book.cakephp.org/3/en/orm/table-objects.html |
# |
Jul 15th 2021, 22:42 |
jh |
or ->getTable() |
# |
Jul 15th 2021, 22:41 |
jh |
`$posts->comments->getTableName()` or simiar |
# |
Jul 15th 2021, 22:41 |
jh |
$tableClass->{'AssociationName')->getTableName() or similar |
# |
Jul 15th 2021, 22:39 |
jh |
oh just the table name |
# |
Jul 15th 2021, 22:38 |
jh |
get a table class instance |
# |
Jul 15th 2021, 22:38 |
jh |
setup has-many/belongs to |
# |
Jul 15th 2021, 15:31 |
sibusiso |
Resolving by doing the following: ```public function getForeignTable($column) { if ('_id' === substr($column, -3)){ $column = substr($column, 0, -3); } return Inflector::classify($column); }``` |
# |
Jul 15th 2021, 15:05 |
cnizzardini |
np, for really basic stuff I just have a shell script that i run which does all that plus runs migrations and whatever else i need. For more elaborate stuff i use github actions (or jenkins if i have to). but you don't need to worry about elaborate stuff for now. |
# |
Jul 15th 2021, 14:56 |
davidmckenzie2015 |
Yes, I agree thanks - webapp dev is a side gig - so I have some learning and refresh to do on git - thanks for the help. |
# |
Jul 15th 2021, 14:49 |
cnizzardini |
`git pull andand composer install --no-dev` and possibly some bin/cake cache clear commands added on is enough to deploy small/basic apps |
# |
Jul 15th 2021, 14:47 |
cnizzardini |
you should just learn git |
# |
Jul 15th 2021, 14:20 |
davidmckenzie2015 |
Thanks, I'll check out using rync. |
# |
Jul 15th 2021, 14:14 |
admad |
You can also use rsync to upload files to server which would be blazing fast compared to FTP |
# |
Jul 15th 2021, 13:57 |
davidmckenzie2015 |
Ya, disk space was a primary concern. Sounds like it will be better to have each webapp have its one set of cakephp files. Looks like I need to find some tutorials on how to use git hub and/or composer to manage the files on the server w/o having to transfer using an FTP client - that takes forever. Thanks for the help and tips. |
# |
Jul 15th 2021, 13:56 |
sibusiso |
Hi everyone, Quick question: given a column name like "product_id," is there a simple built-in function that will return "Products" as a foreign table? Thanks you |
# |
Jul 15th 2021, 13:43 |
cnizzardini |
There is probably some hacky way to do it with symbolic links, but I sense it being a lot of pain for little (any?) gain. What if you need to run cakephp 4.2 for one app and 4.3 for another? What about other dependency issues? Not worth. |
# |
Jul 15th 2021, 11:34 |
hmic |
the simple answer is: you dont. |
# |
Jul 15th 2021, 11:32 |
martin |
``` $this->belongsToMany('Products', [ 'foreignKey' => 'store_id', 'targetForeignKey' => 'product_id', 'through' => 'StoresProducts', 'finder' => 'active', ]);``` like this does not work so I think I also need to create that active filter in Products table, but how do I filter there on the end_date in stores_products |
# |
Jul 15th 2021, 11:27 |
martin |
I’ve a in table `Stores` a BelongsToMany relation ship with `Products`, I did add through to the relation ship, now in the through table there is an end date, so I just want to contain `Products` to the `Store` which are not expired. I already created a finder active in the `StoresProducts` table. but I think I can not use that one with the BelongsToMany? |
# |
Jul 15th 2021, 11:13 |
g.garin20191123 |
Hi everyone! I am from originally Vietnam currently live in Krasnodar, Russia. I am a full stack developer. I can work full time remotely in any time zone. I am looking for full time remote job. Please send me a message if you are looking for a good experienced developer. Thank you, Gavril. |
# |
Jul 15th 2021, 09:58 |
dereuromark |
right right |
# |
Jul 15th 2021, 09:54 |
eax |
Schema was the way forward :+1: |
# |
Jul 15th 2021, 09:54 |
eax |
@dereuromark That only returns the changed values, but thanks :) |
# |
Jul 15th 2021, 09:53 |
dereuromark |
$entity->toArray()? :) |
# |
Jul 15th 2021, 09:52 |
eax |
Sadly it does not, but good idea with the schema, trying that thanks! :) |
# |
Jul 15th 2021, 09:52 |
Martin` |
and you can also read the table schema I think |
# |
Jul 15th 2021, 09:51 |
Martin` |
it is not really a array, but it acts as one :P |
# |
Jul 15th 2021, 09:51 |
Martin` |
does `foreach ($entity as $k => $v)` not work? or array_get_keys() ? |
# |
Jul 15th 2021, 09:49 |
eax |
Hey folks :) In Cake3.8, is there a way to get the name of all the fields in an entity? |
# |
Jul 15th 2021, 06:30 |
alamnaryab |
fixed now, I was passing wrong foreign key values. |
# |
Jul 15th 2021, 06:21 |
alamnaryab |
For my above issue, I was mistakenly assigning user_ids instead of `Student_id` and `Guardian_id` so it is solved now. |
# |
Jul 15th 2021, 06:05 |
rudy1976s |
Hello good morning! I am baking some seed for my plugin: I am creating using bake: my plugin is located in vendor but the bake sometimes creates seeds in app plugin folder and sometimes in the correct path; is there a way to set path for plugin baking ? |
# |
Jul 15th 2021, 05:59 |
alamnaryab |
Good Morning I have school project, on admission entry process, I have to enter `Students` `Guardians` also I have to add `Users` entries for both to allow them login the application. there is student2Guardian relationship table, for which model is named as `StudentGuardians` which has `student_id` and `guardian_id` fields as foreign keys. I am doing all these insertions within a Transaction (to save all or none) all is good |
# |
Jul 15th 2021, 05:59 |
slackebot2 |
until I try to save `StudentGuardian` , because here I am passing `student_id` and `guardian_id` which is not yet committed to database so it is throwing error that these values does not exist in master tables. How can I handle this situation. |
# |
Jul 15th 2021, 05:37 |
admad |
Disk space is the cheapest metric unless you are gonna deploy on a floppy disk. |
# |
Jul 15th 2021, 05:36 |
admad |
Yeah 1.3 predates composer, so that's a different thing. |
# |
Jul 15th 2021, 05:22 |
greg138 |
I used to do it that way with Cake 1.3 apps, and it worked okay, more or less, but it did cause problems. And with the rearrangement of files for autoloading and PSR compliance in Cake 3+, it's much harder to do, and causes more problems to try it. Remember that the day you need to update Cake because you need support for some new plugin in one app, but can't update it because some old plugin in a different app doesn't work |
# |
Jul 15th 2021, 05:22 |
slackebot2 |
with the latest version, your whole setup goes right out the window. If you're hoping to save some disc space, the effort to do so is not worth it. If you're thinking it'll save time when you do updates, composer really minimizes how long it takes, so time savings are again very probably not worth it. |
# |
Jul 15th 2021, 05:11 |
admad |
What's your reason for wanting to use only one vendor folder? |
# |
Jul 15th 2021, 04:08 |
davidmckenzie2015 |
I just don't want to have three (for example) cakephp core folders to support three cakephp webapps. Thanks again. |
# |
Jul 15th 2021, 04:07 |
davidmckenzie2015 |
Yes, I have read cakephp.org and implemented examples there. |
# |
Jul 15th 2021, 04:06 |
davidmckenzie2015 |
Thanks for getting back to me. Yes, I should have been more clear. I want to use a single cakephp install on the server and run multiple webapps from that same cakephp core set of files (e.g. the vendor folder, Bin, etc.) |
# |
Jul 15th 2021, 02:46 |
cnizzardini |
There is this for a more concrete example: https://github.com/gothinkster/cakephp-realworld-example-app |
# |
Jul 15th 2021, 02:44 |
cnizzardini |
Obviously you have read https://cakephp.org/ right? That is your best resource. |
# |
Jul 15th 2021, 02:43 |
cnizzardini |
Do you mean entirely different applications (i.e. different controllers, models etc.)? |
# |
Jul 15th 2021, 02:43 |
cnizzardini |
"host multiple apps" could mean a lot of things. |
# |
Jul 14th 2021, 23:01 |
davidmckenzie2015 |
Can someone please point me to online resources for how to manage cakephp on a production server and have it host multiple apps using the same cakephp core files (version)? I also need help making sure I place the files in the correct directories so that everything is secure. Thanks. |
# |
Jul 14th 2021, 16:39 |
rightscoreanalysis |
Am I correct in saying that $this->Model->getInsertId() is risky.... If user A makes a save and then user B makes a save right after, getInsertId is not going to be user A's insert id? the last insert id is the db connection or the current controller execution... this is Cake v2 btw |
# |
Jul 14th 2021, 15:59 |
tyler.adam.lazenby |
but good to see you |
# |
Jul 14th 2021, 15:59 |
tyler.adam.lazenby |
I was so confused |
# |
Jul 14th 2021, 15:59 |
cnizzardini |
oops wrong chat |
# |
Jul 14th 2021, 15:57 |
cnizzardini |
Did you try this instead: |
# |
Jul 14th 2021, 10:01 |
eax |
Found that solution on github not three minutes ago :P |
# |
Jul 14th 2021, 10:01 |
eax |
Thanks @matsaku! I ended up doing. this instead: `$this->ModelName->getEventManager()->off('Model.beforeSave');` |
# |
Jul 14th 2021, 09:55 |
kevin.pfeifer |
you can pass a custom option to your ```$articles->save($article, ['doNotBeforeSave' => false]);``` and check in your `beforeSave(EventInterface $event*,* EntityInterface $entity*,* ArrayObject $options)` function if that option is set and then just return true like ```if(!empty($options['doNotBeforeSave']) andand $options['doNotBeforeSave']) return true;``` |
# |
Jul 14th 2021, 09:46 |
eax |
Hey folks! Cake3 question: Can I disable a beforeSave event from a model somehow? I looked at the examples in the Cookbook but couldn’t make sense of how to apply them here :$ |
# |
Jul 14th 2021, 08:14 |
rudy1976s |
the listeners is set up in a plugin, I forgot to mention and it is loaded in the plugin.php of the plugin |
# |
Jul 14th 2021, 08:14 |
rudy1976s |
hello all ! I have a problem related to events that I was not yet able to manage: I have a controller action where I create an event and dispatch it: i cannot figure out why it randomly fires; i have a listener registered to that event. In the same controller I have another event, in another action which fires every time without any issue. |
# |
Jul 14th 2021, 07:19 |
dereuromark |
The existing alternatives are listed in https://github.com/FriendsOfCake/awesome-cakephp#queue |
# |
Jul 14th 2021, 07:17 |
dereuromark |
@gautam If you googled, and didnt find anything but that old core ticket, then the answer is most likely "not yet", but you could easily find existing libs out there (e.g. google finds https://github.com/lanlin/codeigniter-swoole ) and you could quickly port this to CakePHP and create a plugin for it yourself. |
# |
Jul 14th 2021, 03:53 |
hmic |
You will need to load the data yourself |
# |
Jul 14th 2021, 03:31 |
gautam |
Do we have any integration of swoole with cakephp? |
# |
Jul 14th 2021, 03:04 |
admad |
If the entity doesn't already have the related record you obviously need to load it yourself. |
# |
Jul 13th 2021, 23:20 |
rightscoreanalysis |
or do I have to load the model in the event and do a findbyid? |
# |
Jul 13th 2021, 22:55 |
rightscoreanalysis |
is this possible? |
# |
Jul 13th 2021, 22:55 |
rightscoreanalysis |
eg $entity->foo->title, but of course the entity only has foo_id |
# |
Jul 13th 2021, 22:54 |
rightscoreanalysis |
I have an event listener setup on my model save, but I need the title attribute of a related model... |
# |
Jul 13th 2021, 20:40 |
kevin.pfeifer |
would be a nice addition to https://book.cakephp.org/migrations/2/en/index.html |
# |
Jul 13th 2021, 20:39 |
greg138 |
I don't know if it's in the docs. It's in my code, but it might have gotten there by me searching the source, not the docs. :) |
# |
Jul 13th 2021, 20:20 |
dereuromark |
if this isnt in the docs, maybe it should be :) |
# |
Jul 13th 2021, 19:11 |
greg138 |
`$migrations = new \Migrations\Migrations();` `$migrations->seed(['plugin' => 'MyPlugin', 'seed' => 'MySeed']);` |
# |
Jul 13th 2021, 19:05 |
richard |
makes my life easier |
# |
Jul 13th 2021, 19:05 |
richard |
what i do is create a masterseed that runs all the other seeds, i also have checks in each seed so re-running won’t produce duplicate records |
# |
Jul 13th 2021, 18:28 |
devito |
is it possible to change the default layout of a plugin without modifying the plugin its self? |
# |
Jul 13th 2021, 17:48 |
tyler.adam.lazenby |
yeah |
# |
Jul 13th 2021, 17:48 |
dereuromark |
genius :) I would probably still prefer to have also a more code native way to run them. Might be worth a PR some day for someone. |
# |
Jul 13th 2021, 17:47 |
tyler.adam.lazenby |
```public function runSeed($name) { exec(join(DS, ['bin', 'cake']) . " migrations seed --seed=$name"); }``` |
# |
Jul 13th 2021, 17:47 |
tyler.adam.lazenby |
for me this works fine |
# |
Jul 13th 2021, 17:34 |
tyler.adam.lazenby |
if this doesn't work |
# |
Jul 13th 2021, 17:34 |
tyler.adam.lazenby |
i might |
# |
Jul 13th 2021, 17:34 |
tyler.adam.lazenby |
hmmmmm |
# |
Jul 13th 2021, 17:33 |
kevin.pfeifer |
You could try to get some code snippets from https://github.com/cakephp/migrations/blob/master/src/AbstractSeed.php#L72 Which basically is the function to call one seed inside of another |
# |
Jul 13th 2021, 17:30 |
tyler.adam.lazenby |
nevermind |
# |
Jul 13th 2021, 17:30 |
tyler.adam.lazenby |
oh wait |
# |
Jul 13th 2021, 17:30 |
tyler.adam.lazenby |
and I can't call DS here |
# |
Jul 13th 2021, 17:29 |
tyler.adam.lazenby |
and the \ should be \ in windows but it should / on linux |
# |
Jul 13th 2021, 17:29 |
tyler.adam.lazenby |
the problem with that is that I am developing on windows for a machine that is in linux |
# |
Jul 13th 2021, 17:29 |
tyler.adam.lazenby |
the hax way huh? |
# |
Jul 13th 2021, 17:28 |
dereuromark |
exec() :P |