# |
Jul 21st 2017, 16:08 |
jeremyharris |
the other solution would be to change the default connection name in your tables (if you extend the table this would be easy) |
# |
Jul 21st 2017, 16:07 |
jeremyharris |
you’d have to dropAlias when done though |
# |
Jul 21st 2017, 16:07 |
jeremyharris |
similar to how cake sets an alias during tests (so that default resolves to the test connection instead): ConnectionManager::alias(‘otherConnection’, ‘default’) |
# |
Jul 21st 2017, 16:05 |
viraj.khatavkar |
How do I do that? I am sorry but I am not getting what you are trying to say exactly |
# |
Jul 21st 2017, 16:05 |
jeremyharris |
you could create a connection alias for the default connection to point to the other one |
# |
Jul 21st 2017, 16:03 |
viraj.khatavkar |
Not for a specific table. I want it to run using a different connection for all of it’s methods |
# |
Jul 21st 2017, 16:01 |
jeremyharris |
@viraj.khatavkar I believe you change the connection on the table |
# |
Jul 21st 2017, 15:59 |
viraj.khatavkar |
Hi, I was wondering how do I tell the ORM in runtime to use a specific connection. |
# |
Jul 21st 2017, 15:46 |
gutts |
sweet, thank you neon1024 |
# |
Jul 21st 2017, 15:46 |
neon1024 |
:P |
# |
Jul 21st 2017, 15:46 |
neon1024 |
Then,, er Collection! |
# |
Jul 21st 2017, 15:46 |
neon1024 |
Then use a resultsMap function |
# |
Jul 21st 2017, 15:45 |
neon1024 |
Then use matching to filter the comments by author |
# |
Jul 21st 2017, 15:45 |
neon1024 |
As you could also contain Authors for Posts and Comments separately if you wanted using the same table instance, because the ORM is awesome like that :) |
# |
Jul 21st 2017, 15:44 |
neon1024 |
Hopefully the parenthesis match up! ;P |
# |
Jul 21st 2017, 15:44 |
neon1024 |
This is the kind of thing I’d do :slightly_smiling_face: |
# |
Jul 21st 2017, 15:44 |
neon1024 |
https://gist.github.com/davidyell/a1fe56cc13481d2336f03cffc745d4ed |
# |
Jul 21st 2017, 15:42 |
gutts |
an assoc. array explicitly overrides the entire thing, makes sense |
# |
Jul 21st 2017, 15:42 |
gutts |
that changes the behaviour of things |
# |
Jul 21st 2017, 15:42 |
gutts |
wait, i was feeding an associative array instead of a list |
# |
Jul 21st 2017, 15:42 |
neon1024 |
1 sec, I’ll write it in a Gist for ease :slightly_smiling_face: |
# |
Jul 21st 2017, 15:41 |
gutts |
if I do ->select(['id', 'title']) it wipes out 'comments' I think |
# |
Jul 21st 2017, 15:41 |
gutts |
, neon1024 |
# |
Jul 21st 2017, 15:41 |
gutts |
i want 'id' and 'title' from Posts/$this, but i still want 'comments' => [ ['author' => 'blah' ] ] |
# |
Jul 21st 2017, 15:41 |
neon1024 |
Just trying to track down why my find() on the instance returns NULL really |
# |
Jul 21st 2017, 15:40 |
neon1024 |
I’m not entirely happy with lines 13 and 14 anyway, I think I might store the instance in a better way, or pass it around |
# |
Jul 21st 2017, 15:39 |
gutts |
basically |
# |
Jul 21st 2017, 15:39 |
gutts |
so do the select first |
# |
Jul 21st 2017, 15:39 |
neon1024 |
Yep |
# |
Jul 21st 2017, 15:39 |
neon1024 |
@gutts Yes, like `$this->Examples->find()->select([‘id’, ‘name’])->contain([‘Foo’ => function ($q) { return $q->select([‘Foo.id’, ‘Foo.name’]); }]); |
# |
Jul 21st 2017, 15:39 |
gutts |
where I want the latter part of that to be Posts.id/Posts.title |
# |
Jul 21st 2017, 15:39 |
gutts |
like if my current model is Posts and I do $this->find()->contain(['COmments' => function($q) { return $q->select(['author']) }])->select(['id', 'title']) |
# |
Jul 21st 2017, 15:38 |
jay |
I'd prefer line 12 to be the only line in the try {} |
# |
Jul 21st 2017, 15:37 |
neon1024 |
Ah yeah, I am to a degree, but it doesn’t check for Cake\ORM\Table |
# |
Jul 21st 2017, 15:37 |
gutts |
neon1024: you mean specify the "current" model selects in contain? |
# |
Jul 21st 2017, 15:36 |
neon1024 |
Ahh, perhaps I am! |
# |
Jul 21st 2017, 15:36 |
jeremyharris |
@neon1024 looks like you’re rewriting the ModelAwareTrait? |
# |
Jul 21st 2017, 15:36 |
neon1024 |
You have to put a `->select()` into your contain :slightly_smiling_face: |
# |
Jul 21st 2017, 15:36 |
gutts |
if I do something like $this->find()->contain()->select(['id' => 'id']) the relational fields go away. tried to specify them to no avail |
# |
Jul 21st 2017, 15:35 |
gutts |
i'm selecting specific fields in my $this->find()->contains(['Table' => function($q) { } ]) expressions, but I also want my main model to selectively select certain fields. how can I "retain" my relational selects? |
# |
Jul 21st 2017, 15:35 |
neon1024 |
@inoas I’m sure we talked about this before and you had something right? |