# |
Aug 26th 2016, 08:33 |
JohnWayne |
$groups = $groupsT->find('list', ['limit' => 200])->where(['Groups.type' => 'partner'])->toArray(); |
# |
Aug 26th 2016, 08:33 |
JohnWayne |
How can I sort list in query? |
# |
Aug 26th 2016, 08:31 |
dwikisaputra48 |
how to use routing in file js (CakePHP 3) example : ?php echo Router::url(['controller' => 'users', 'action' => 'index']); ? |
# |
Aug 26th 2016, 08:30 |
lorenzo |
dwikisaputra48 I did not understand your question, what do you mean? |
# |
Aug 26th 2016, 08:30 |
lorenzo |
Not sure what the purpose of getting the result of that method is fquffio |
# |
Aug 26th 2016, 08:29 |
dwikisaputra48 |
hello ... soryy, i have a question. how to create routing in file js (CakePHP 3) thx |
# |
Aug 26th 2016, 08:24 |
fquffio |
Yeah, that I would have implemented for sure. I'll try with configuration. Last question: what if an inverse association hasn't been configured at all? :) I know it might sound kinda strange, but isn't there any way to obtain the result of `SelectableAssociationTrait::_buildQuery()` (without doing fancy things like exposing it with a ReflectionObject and other things people under the age of 18 shouldn't do)? |
# |
Aug 26th 2016, 08:22 |
lorenzo |
you donâ??t want people having all the power of SQL from their browsers |
# |
Aug 26th 2016, 08:21 |
lorenzo |
having control using a whitelist on what the end user is allowed to do is a great thing |
# |
Aug 26th 2016, 08:21 |
fquffio |
:+1: |
# |
Aug 26th 2016, 08:21 |
lorenzo |
thatâ??s also a good idea from the perspective of performance and security |
# |
Aug 26th 2016, 08:21 |
fquffio |
Uhmâ?¦ So I'd have to look up in some configuration array which inverse association corresponds to the association passed. |
# |
Aug 26th 2016, 08:21 |
lorenzo |
make it require Association and a some config describing what is possible |
# |
Aug 26th 2016, 08:20 |
fquffio |
I'm trying to do this with command pattern, as the app will soon start to become slightly complicated. I have a command `ListAssociated`, and I'd like it to basically need only the `Association` object (and the primary key of the object to find relationships for, of course). |
# |
Aug 26th 2016, 08:19 |
lorenzo |
and use that config, instead of building everything dynamically |
# |
Aug 26th 2016, 08:19 |
lorenzo |
have a place where you declare the allowed paths, and some meta information for the path it is allowed to be traversed |
# |
Aug 26th 2016, 08:19 |
lorenzo |
since you are not implementing a generic library, the add some configuration to it |
# |
Aug 26th 2016, 08:18 |
fquffio |
I know. :) |
# |
Aug 26th 2016, 08:18 |
lorenzo |
thatâ??s the problem with overly dynamic and generic code, it is difficult to build and get right. Whereas just implementing the specific use case you need is significantly easier |
# |
Aug 26th 2016, 08:18 |
fquffio |
@lorenzo: In many cases I could, but not always. For instance, `Posts` could be related to `Users` twice: `CreatedBy` and `ModifiedBy`. |
# |
Aug 26th 2016, 08:17 |
lorenzo |
and find the one you need? |
# |
Aug 26th 2016, 08:17 |
lorenzo |
canâ??t you iterate $table->associations() ? |
# |
Aug 26th 2016, 08:17 |
fquffio |
Uhm, well.. I'm basically implementing JSON API. I have and endpoint `/posts/1/relationships/foos` that should return a list of all entities linked to the post with ID=1. |
# |
Aug 26th 2016, 08:14 |
voycey |
generally if you have set up your ERD properly from the beginning it should all work pretty smoothly |
# |
Aug 26th 2016, 08:14 |
voycey |
Im sure you have a use case for it but I cant work out what it is, I dont think I have ever had to do what you are doing in a lot of years of using cake, saying that I could just be completely misunderstanding what you are trying to do |
# |
Aug 26th 2016, 08:12 |
slackebot |
association. But in my scenario, I only know the name of Posts->Comments association. |
# |
Aug 26th 2016, 08:12 |
fquffio |
Yeah, but in some cases the FK isn't in the target table. BelongsToMany associations have a joint table, that somehow needs to be added to the query in the JOIN clause in order to achieve the result. The `::matching()` method does exactly this: it adds conditions and joins (if needed) depending on the type of association you are dealing with. But in order to find Comments that are linked to a specific Post, you need to know the name of the Co |
# |
Aug 26th 2016, 08:08 |
voycey |
you can do conditional associations through the model layer already and you can build these on the fly if required |
# |
Aug 26th 2016, 08:08 |
voycey |
I dont really understand what you mean - the whole point of associations are that they are based off primary and foreign keys |
# |
Aug 26th 2016, 08:08 |
fquffio |
Also, conditional associations would need to be treated in a special manner, as I'd have to manually add the finder. |
# |
Aug 26th 2016, 08:07 |
fquffio |
@voycey First of all, thanks. :slightly_smiling_face: Well, your solution would work well for HasMany and HasOne associations. But I wish I could support _any_ type of association in a transparent way, thus I'd expect to interact with the `Association` object to act consistently. |
# |
Aug 26th 2016, 08:06 |
voycey |
$this->Comments->find |
# |
Aug 26th 2016, 08:06 |
voycey |
or sorry |
# |
Aug 26th 2016, 08:05 |
voycey |
? |
# |
Aug 26th 2016, 08:05 |
voycey |
why cant you just do $this->Posts->find()->where(['post_id' => $postId])->contain->(['Foo']) |
# |
Aug 26th 2016, 08:03 |
slackebot |
duplicating ORM logic. I have obtained an acceptable result calling `TableRegistry::get('Posts')->get($postId, ['contain' => ['Foo']])->get('foo')`, but this is an array of already hydrated entities, while I need to get the query object in order to paginate results. Thanks aforehand! |
# |
Aug 26th 2016, 08:03 |
slackebot |
Post. If I knew the name of the inverse association (`Bar`), that would be easily feasible using `TableRegistry::get('Comments')->find()->matching('Bar', function($q) { ... });`. Unfortunately, in this context I have no way of knowing the name of the inverse association. Is there any way of achieving the same result? I saw that `SelectableAssociationTrait::_buildQuery()` does pretty much the kind of thing I need, but it is a protected method, and I'd |
# |
Aug 26th 2016, 08:03 |
fquffio |
Hello everybody! Sorry to be obsessiveâ?¦ I asked this very same question yesterday, but I got no answer, so I'll have one last try. :) I have a table, say `Posts`, that is linked to a second table, say `Comments`, via an association named `Foo`. The inverse association (Comments -> Posts) potentially has a completely different name that doesn't follow any convention, say `Bar`. I need to obtain a Query object to find Comments that are rela |
# |
Aug 26th 2016, 07:55 |
birdy247 |
Morning :slightly_smiling_face: |
# |
Aug 26th 2016, 05:28 |
unorthodox |
Morning |
# |
Aug 26th 2016, 04:40 |
voycey |
Does anyone on here use Swagger? |