# |
Jun 26th 2021, 15:35 |
mokiwaa |
stile there? |
# |
Jun 26th 2021, 15:16 |
kevin.pfeifer |
yes |
# |
Jun 26th 2021, 15:10 |
mokiwaa |
someone online? |
# |
Jun 26th 2021, 15:09 |
mokiwaa |
Hi |
# |
Jun 26th 2021, 14:33 |
kevin.pfeifer |
from a quick read through I would also say that this data should be present in the junction table between the 2 main tables. And only the junction table has the foreign keys for the 2 main tables - therefore as Zuluru already said a `belongsToMany` |
# |
Jun 26th 2021, 14:19 |
greg138 |
It sounds like this should be a `belongsToMany` association for both models, meaning that Answers is the join table. Am I missing something? |
# |
Jun 26th 2021, 13:48 |
slackebot |
Recommendation to the Answer and landed on this current solution. What do you guys and gals think? |
# |
Jun 26th 2021, 13:48 |
slackebot |
which has foreign keys for Assessment and Recommendation plus the extra data. When I create an Assessment record I use beforeMarshal to create an Answer for each Recommendation that was selected for the Assessment. While this works, it seems a little 'hacky'. Can anyone see a better way to achieve this outcome? I had originally tried with addition join table data but I couldn't figure out a way to join both the Assessment and |
# |
Jun 26th 2021, 13:48 |
tomrwaller |
Hey everyone, just wanted to ask for some advice about how I'm currently doing my associations and whether anyone thinks there is a better way. I currently have Assessments and Recommendations. An Assessment has many Recommendations and a Recommendation can belong to many Assessments. I want to store answers to Recommendations for each Assessment. Just a couple of fields maybe up to 10. At the moment I have a Answers model |
# |
Jun 25th 2021, 17:03 |
ricmelero |
Thank @admad and @kevin.pfeifer! |
# |
Jun 25th 2021, 17:01 |
ricmelero |
never mind, I got it working now, later this year I expect to have fewer work and I may take a look into routing, I have noticed a few cases that are weird or may be improved (like redirecting to array styles named routes) and I'll loved to help... |
# |
Jun 25th 2021, 16:56 |
steinkel |
we usually rely on any of the https://github.com/CakeDC/cakephp-api/tree/master/src/Service/Auth/Authenticate for API based applications |
# |
Jun 25th 2021, 16:56 |
nick.vanderwoude |
@steinkel I did see that. Is it working? |
# |
Jun 25th 2021, 16:55 |
steinkel |
@nick.vanderwoude we did some work time ago to provide a specific endpoint for ajax login here https://github.com/CakeDC/users/pull/789 |
# |
Jun 25th 2021, 16:55 |
ricmelero |
although placeholder length is arbitrary... mm |
# |
Jun 25th 2021, 16:54 |
ricmelero |
and there is no attemp to trying to check longer first.. even that I understand that it may have placeholders or dinamyc parts |
# |
Jun 25th 2021, 16:53 |
ricmelero |
yep, I see that krsort, is present in a few places.. and yes @admad, I get that, and that's why I was thinking about it, inside each path, you may have many routes |
# |
Jun 25th 2021, 16:52 |
admad |
But you lose that optimization for lang routes since they start with a placeholder |
# |
Jun 25th 2021, 16:51 |
kevin.pfeifer |
i guess you mean that krsort https://github.com/cakephp/cakephp/blob/master/src/Routing/RouteCollection.php#L130 |
# |
Jun 25th 2021, 16:51 |
admad |
It does sort them by *static* longer parts first. |
# |
Jun 25th 2021, 16:50 |
ricmelero |
but besides that case, I was thinking that routes is trying to check longer paths first, ordering that way, but inside each path, this behavior does not apply... wouldn't be that a desired behavior? I mean, inside each path, sort routes with longer names or templates first.. I may work in a PR if that's the case |
# |
Jun 25th 2021, 16:47 |
ricmelero |
this way is cleaner |
# |
Jun 25th 2021, 16:47 |
ricmelero |
I had moved all inside Plugin::routes() method to my routes.php, also worked, but it wasn't feel rigth |
# |
Jun 25th 2021, 16:45 |
ricmelero |
yeah, that did the trick, |
# |
Jun 25th 2021, 16:44 |
admad |
you can use `$routes->loadPlugin('Foo')` at the top of your `routes.php` to load the plugin's route first. |
# |
Jun 25th 2021, 16:43 |
ricmelero |
I can get it working, but it feel like a hack |
# |
Jun 25th 2021, 16:43 |
ricmelero |
so, they are loaded after app routes |
# |
Jun 25th 2021, 16:42 |
ricmelero |
I've app routes defined in config/routes.php, but plugin routes are in each plugin's Plugin::routes() method |
# |
Jun 25th 2021, 16:41 |
admad |
Just overly generic routes are bound to cause you problems. |
# |
Jun 25th 2021, 16:40 |
admad |
> sorry, it's like this "/{lang}/{controller}/{action}/*" Well then no wonder it matches, fix your routes order. |
# |
Jun 25th 2021, 16:39 |
ricmelero |
may I attach an image here? |
# |
Jun 25th 2021, 16:39 |
kevin.pfeifer |
but your `/{lang}/admin/{controller}/{action}` route is present above the blue one? |
# |
Jun 25th 2021, 16:38 |
ricmelero |
@kevin.pfeifer yep |
# |
Jun 25th 2021, 16:38 |
kevin.pfeifer |
so if you enable debugkit and check the “Routes” tab the wrong route is marked blue? |
# |
Jun 25th 2021, 16:37 |
ricmelero |
that's why it matchs |
# |
Jun 25th 2021, 16:37 |
ricmelero |
sorry, it's like this "/{lang}/{controller}/{action}/*" |
# |
Jun 25th 2021, 16:34 |
admad |
> /es/admin/users/view/1 is matching with /{lang}/{controller}/{action} @ricmelero I don't see how that's possible since your URL has 4 parts while the route has just 3 (and there's no `/*` at the end). And even if that's the case just connect your routes for admin prefix earlier. |
# |
Jun 25th 2021, 16:25 |
nick.vanderwoude |
@ndm That's good advice, thanks. I was able to make some progress from newing up my own new Response object in the controller and returning that. It prevents the api endpoint from getting redirected, which is better, but I am still having issues getting the data out on the front end |
# |
Jun 25th 2021, 16:10 |
slackebot |
whatever you want. But since that's coming from someone who's not familiar with the plugin, take it with a grain of salt. |
# |
Jun 25th 2021, 16:10 |
ndm |
@nick.vanderwoude I'm not overly familiar with the plugin, but looking at the code, the redirects seem pretty much hardcoded. https://github.com/CakeDC/users/blob/master/src/Controller/Component/LoginComponent.php#L145 You could probably provide a custom `login()` action, require the trait's method in an aliased fashion, invoke it manually and extract the required information from the returned response, then you can do with it |
# |
Jun 25th 2021, 16:09 |
ricmelero |
I was debbuging and I saw that all routes ended up under "/" path in the routes collection, so the revert sorting to move longer paths first, does nothing, and inside that path, plugin routes are added after, so is matching the shorter first, without plugin prefix |