# |
Aug 25th 2016, 16:55 |
fquffio |
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. |
# |
Aug 25th 2016, 16:52 |
slackebot |
inverse relationship. 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 prefer not duplicating ORM logic. |
# |
Aug 25th 2016, 16:52 |
fquffio |
Hello everybody! I have a table, say `Posts`, that is related to a second table, say `Comments`, via a relation named `Foo`. I need to obtain a Query object to find Comments that are related to a specific Post. If I knew the name of the inverse relationship (`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 |
# |
Aug 25th 2016, 16:50 |
marquesf |
first code is display,ctp |
# |
Aug 25th 2016, 16:49 |
marquesf |
@btx what i miss? https://gist.github.com/anonymous/202a4503e603cc0d2192d37f8bcd7cd1 |
# |
Aug 25th 2016, 16:42 |
shealyw2 |
should you pass associated to newEntity and patchEntity? or just patchEntity? |
# |
Aug 25th 2016, 16:38 |
admad |
Validation is done when marshalling not saving |
# |
Aug 25th 2016, 16:17 |
btx |
so it appears there is no way to have `save()` only honor a requested validation set? (e.g. admin validation is different from user level validaton) |
# |
Aug 25th 2016, 16:14 |
btx |
and ``` $this->save($e, [â??validateâ??=>â??consumeâ??]); ``` does nothing |
# |
Aug 25th 2016, 16:13 |
btx |
will a `Table` always call `validationDefault` ? when I do ```php $e = $this->newEntity($data, [â??validateâ??=>â??consumeâ??]); return $this->save($e); ``` it appears that both the `validationDefault` and `validationConsume` functions are being called. |
# |
Aug 25th 2016, 16:10 |
btx |
np, Cells are like microcontrollers - more here http://book.cakephp.org/3.0/en/views/cells.html |
# |
Aug 25th 2016, 16:10 |
btx |
`?= $this->cell(â??Contact::addâ??) ?>` and then your view cell acts like a tiny controller and passes an entity to the view cell `.ctp` file that is picked up by `$this->Form-create($contact)` |
# |
Aug 25th 2016, 16:10 |
marquesf |
@btx thank u bro i will search about |
# |
Aug 25th 2016, 16:08 |
btx |
@marquesf view Cell that spits out a form using the correct entity object is one way |
# |
Aug 25th 2016, 16:07 |
marquesf |
i want to use the add action from my contatcs controller in my home controller any tricks to do it? |
# |
Aug 25th 2016, 16:06 |
ypnos |
have a look at https://packagist.org/packages/ypnos-web/cakephp-datatables maybe |
# |
Aug 25th 2016, 16:03 |
jaywalker |
Hmm, that might prove useful. Thanks |
# |
Aug 25th 2016, 15:59 |
ypnos |
I use datatables with scroller |
# |
Aug 25th 2016, 15:59 |
ypnos |
I hate pagination |
# |
Aug 25th 2016, 15:58 |
jaywalker |
How do you guys usually go about making an index/paginated page from data that's not represented 1-to-1 as a model/db table? |
# |
Aug 25th 2016, 15:23 |
dereuromark |
As $request->query becomes deprecated and one has to use $request->query() anyway |
# |
Aug 25th 2016, 15:22 |
dereuromark |
@btx In light of https://github.com/cakephp/cakephp/issues/9325 this becomes actually necessary to do now in 3.current |
# |
Aug 25th 2016, 15:18 |
dereuromark |
its a small feature for current master to allow that IMO |
# |
Aug 25th 2016, 15:18 |
dereuromark |
btx you wanna make a PR here? |
# |
Aug 25th 2016, 14:57 |
ypnos |
) |
# |
Aug 25th 2016, 14:57 |
ypnos |
btw I don't mind you write $a = find(); $a->morestuff($a->foo)), all I complained about was $a = find(); $a = $a->morestuff :9 |
# |
Aug 25th 2016, 14:55 |
ypnos |
I would always do the latter, basically because I like to abstract away all SQL code and be database agnostic, but I think it is a matter of taste |
# |
Aug 25th 2016, 14:54 |
saliak |
ypnos: yeah, in my current implementation, for sure (done actually). but if i wanted to implement my sum() function like in http://book.cakephp.org/3.0/en/orm/query-builder.html#using-sql-functions, instaad fo â??releasedâ??=>â??sum(fulfillmentItems.qtyâ??, to do â??releasedâ??=>$warehouse_skus->func()->sum(â??FulfillmentItems.qtyâ??), is a little easier. is there a benefit to doing the latter over the former? |
# |
Aug 25th 2016, 14:52 |
ypnos |
all I'm saying is cut the assignment from your statement, it is redundant, serves no purpose |
# |
Aug 25th 2016, 14:51 |
ypnos |
well what is the benefit of writing $variable = $variable? |
# |
Aug 25th 2016, 14:51 |
saliak |
ypnos: so I created a separate finder variable before. is there a downside to doing the function as I did? |
# |
Aug 25th 2016, 14:50 |
saliak |
ypnos: oh yeah, i previouly was doing the sum as $warehouse_skus->func->sum(â??FulfillmentItems.qtyâ??) |
# |
Aug 25th 2016, 14:50 |
ypnos |
yeah I saw you were confused with these two methods |
# |
Aug 25th 2016, 14:49 |
saliak |
ypnos: cool thanks.. man, i could have sworn i looked at leftJoin beforeâ?¦ must have gotten it mixed with leftJoinWith |
# |
Aug 25th 2016, 14:49 |
ypnos |
you can as well just write $foo->select()-> ... |
# |
Aug 25th 2016, 14:49 |
ypnos |
btw, $warehouse_skus = $warehouse_skus->select(-) is silly |
# |
Aug 25th 2016, 14:48 |
ypnos |
then this is the way to go |
# |
Aug 25th 2016, 14:48 |
ypnos |
ah but I see you have two fields per subquery |
# |
Aug 25th 2016, 14:48 |
ypnos |
easier to write down, code is then more comprehensible |
# |
Aug 25th 2016, 14:47 |
ypnos |
I would still do the select thing in your case probably |
# |
Aug 25th 2016, 14:47 |
ypnos |
yeah thats what I was talking about |