# |
Jul 12th 2017, 15:05 |
jeremyharris |
@pedroseco that looks ok to me, except it’s missing a group clause which you usually need for aggregate functions |
# |
Jul 12th 2017, 15:04 |
jeremyharris |
and the session is started if it needs to be during write() |
# |
Jul 12th 2017, 15:04 |
ericadeefox |
ok I'm gonna try to write this differently then... |
# |
Jul 12th 2017, 15:03 |
jeremyharris |
the request won’t be available until after the integration test method (e.g., get, post) runs so by then it will be too late. but here’s where it’s written: https://api.cakephp.org/3.4/source-class-Cake.TestSuite.IntegrationTestCase.html#546 |
# |
Jul 12th 2017, 15:02 |
pedroseco |
@jeremyharris sure: https://gist.github.com/pedroseco/7f2d0cb0e01361c98fc7cd346f24bc24 |
# |
Jul 12th 2017, 15:02 |
ericadeefox |
@jeremyharris wait does it? wouldn't that mean that one _could_ use `$this->session()` with `session_start()` and it would work? because it totally wasn't working for me so now I'm just trying to figure out how to use `$this->request->session()` |
# |
Jul 12th 2017, 15:00 |
jeremyharris |
@pedroseco maybe I misunderstood. can you gist your query that has the sum on it? |
# |
Jul 12th 2017, 15:00 |
jeremyharris |
@ericadeefox still dealing with FB stuff? :( I was reading the code and the integration test writes the data you pass in $this->session to the session right before dispatching the request |
# |
Jul 12th 2017, 15:00 |
pedroseco |
instead of manipulating the entity on the query object? |
# |
Jul 12th 2017, 14:59 |
pedroseco |
should I use a collection here? |
# |
Jul 12th 2017, 14:59 |
pedroseco |
humm, i did that but now it only returns the first item of the object |
# |
Jul 12th 2017, 14:59 |
jeremyharris |
@pedroseco you can re-select all fields with ->select($this->Table) |
# |
Jul 12th 2017, 14:58 |
pedroseco |
hi guys, im trying to do a sum() on a query object but the result only returns the select field that I appended sum() to. How can I achieve the result with all the fields? |
# |
Jul 12th 2017, 14:48 |
ericadeefox |
ok this is probably the dumbest question of 2017 but is there any way to use `$this->request->session()` in integration testing? because `$this->session()` doesn't actually set `$_SESSION` data or work with `session_start()`, which I need to do in order to test a certain plugin. |
# |
Jul 12th 2017, 14:43 |
sathomsen |
https://book.cakephp.org/3.0/en/orm/validation.html#creating-a-rules-checker |
# |
Jul 12th 2017, 14:42 |
jarard01 |
https://book.cakephp.org/3.0/en/core-libraries/validation.html#conditional-validation |
# |
Jul 12th 2017, 14:42 |
jarard01 |
this right? Westfalia Roof |
# |
Jul 12th 2017, 14:42 |
sathomsen |
You can go with a custom validation rule:) |
# |
Jul 12th 2017, 14:41 |
jarard01 |
how can I apply a validation rule when a foo_type_id = x |
# |
Jul 12th 2017, 14:38 |
sathomsen |
Hey guys, is there any build in way of flattening the error object returned from the entity validation? |
# |
Jul 12th 2017, 14:28 |
josexato |
just to clarify (and sorry if redundant) If bake creates a belongsto relationship I can manually change it to hasone with out compromising the conventions? |
# |
Jul 12th 2017, 14:26 |
neon1024 |
The main difference is that `hasOne` will be returned as an entity in the entity property, rather than an array of entities :slightly_smiling_face: |
# |
Jul 12th 2017, 14:25 |
neon1024 |
But you’re right, there isn’t a database convention for it |
# |
Jul 12th 2017, 14:25 |
neon1024 |
Well, I suppose defining it is forcing it ;) |
# |
Jul 12th 2017, 14:25 |
neon1024 |
There is no forcing it, just define it as such. https://book.cakephp.org/3.0/en/orm/associations.html#hasone-associations |
# |
Jul 12th 2017, 14:25 |
josexato |
https://book.cakephp.org/3.0/en/intro/conventions.html#model-and-database-conventions |
# |
Jul 12th 2017, 14:24 |
josexato |
@neon1024 thanks I'll read the informations, I was asking this because I do not find anything explicit about which convention to use to force the use of hasone instead of belongsto |
# |
Jul 12th 2017, 14:23 |
neon1024 |
I’m sure you can find the AssociationCollection class yourself :P |
# |
Jul 12th 2017, 14:23 |
neon1024 |
https://github.com/cakephp/cakephp/blob/master/src/ORM/Table.php#L200 |
# |
Jul 12th 2017, 14:22 |
jeremyharris |
glad to hear |
# |
Jul 12th 2017, 14:22 |
kim____ |
@jeremyharris the beforeSave worked... thanks! |
# |
Jul 12th 2017, 14:22 |
neon1024 |
https://github.com/cakephp/bake/blob/master/src/View/Helper/BakeHelper.php#L109 |
# |
Jul 12th 2017, 14:22 |
kim____ |
@jeremyharris. |
# |
Jul 12th 2017, 14:21 |
neon1024 |
@josexato It can read the association from the table instance, https://github.com/cakephp/bake/blob/master/src/Template/Bake/Element/Controller/edit.ctp#L16-L17 |
# |
Jul 12th 2017, 14:21 |
josexato |
Hello, one quick question how does bake recognize if the realationship is hasone or belongs to? |
# |
Jul 12th 2017, 14:20 |
jeremyharris |
I’ll say one more time: I suggest you use beforeSave to add the newActivity on the entity, so it will be saved in one transaction and linked automatically |
# |
Jul 12th 2017, 14:19 |
kim____ |
but let me try your beforeSave suggestion. |
# |
Jul 12th 2017, 14:19 |
kim____ |
source entity needs to be persisted before proceeding. |
# |
Jul 12th 2017, 14:19 |
kim____ |
same error |
# |
Jul 12th 2017, 14:19 |
kim____ |
let me try |
# |
Jul 12th 2017, 14:18 |
jeremyharris |
$this->Table->belongsToMany(‘Activities’)->link($entity, [$newActivity]); |