# |
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]); |
# |
Jul 12th 2017, 14:18 |
jeremyharris |
wait |
# |
Jul 12th 2017, 14:17 |
jeremyharris |
ok, I think you want line 12 on your gist to be this: $this->Table->belongsToMany(‘Activities’)->link($newActivity, [$entity]); |
# |
Jul 12th 2017, 14:17 |
kim____ |
but let me try. |
# |
Jul 12th 2017, 14:17 |
kim____ |
if i do that. won't it give an error because the newActivity is not yet created? |
# |
Jul 12th 2017, 14:16 |
jeremyharris |
oh* |
# |
Jul 12th 2017, 14:16 |
jeremyharris |
or, so the problem is link |
# |
Jul 12th 2017, 14:16 |
kim____ |
but not in the join table; |
# |
Jul 12th 2017, 14:16 |
jeremyharris |
I think this is more complicated than it needs to be. It doesn’t look like afterSave is doing anything special from what you pasted, you could just add the entity in beforeSave and it would hook up the foreignKeys and link it automatically |
# |
Jul 12th 2017, 14:16 |
kim____ |
when i look at my database tables. the lead entity is saved as well as the activity |
# |
Jul 12th 2017, 14:14 |
jeremyharris |
well this is weird, why does the Activity have an id at that point in time? I’m really confused here |
# |
Jul 12th 2017, 14:14 |
kim____ |
where can i get the stack trace? |
# |
Jul 12th 2017, 14:11 |
kim____ |
sorry mate. |
# |
Jul 12th 2017, 14:11 |
kim____ |
https://gist.github.com/mccp/82c28fc7f3bd0b1ff9d97452f6863029 |
# |
Jul 12th 2017, 14:10 |
jeremyharris |
while you’re at it, can you gist the full stack trace of the error? |