# |
Nov 6th 2019, 08:44 |
admad |
`'comment_id' => 1` is the same as saving any other field. There's no special handling there. While `_ids` is a special convention |
# |
Nov 6th 2019, 08:42 |
conehead |
just to save it the same way. I get your point. But both are associations and the way they are stored are different |
# |
Nov 6th 2019, 08:41 |
conehead |
I am just saying: you set a `belongsTo` as `'comment_id' => 1`, but a `belongsToMany` as `'comment' => ['_ids' => [1,2,3]]. why not save a `belongsToMany` as `'comment_ids' => [1,2,3]` or a `belongsTo` as `'comment' => ['_id' => 1]` imho that would be more convinient |
# |
Nov 6th 2019, 08:38 |
admad |
that's a hasMany, not belonsTo |
# |
Nov 6th 2019, 08:37 |
conehead |
Or the other way around would be to allow for multiple associations to set e.g. `new Post(['comment_ids' => [1,2,3])` |
# |
Nov 6th 2019, 08:35 |
conehead |
Think it would be common sense that you could handle different associations similar |
# |
Nov 6th 2019, 08:33 |
admad |
why? there's only a single fK value for belongsTo |
# |
Nov 6th 2019, 08:31 |
conehead |
@admad Yes thanks. That works. Just wondering if this example is not a little bit confusing then: https://book.cakephp.org/3/en/orm/saving-data.html#saving-belongsto-associations Something similar like `_ids` would be great I think |
# |
Nov 6th 2019, 08:28 |
pidlo |
something like this? $query->func()->dateAdd('dfrom', @num, 'MONTH') ??? |
# |
Nov 6th 2019, 08:28 |
pidlo |
howto do this 'DATE_ADD(dfrom, INTERVAL - @num MONTH)' |
# |
Nov 6th 2019, 08:28 |
pidlo |
hello all i have registred variable in sql '@num:=CAST(period AS UNSIGNED)', |
# |
Nov 6th 2019, 08:26 |
admad |
@conehead to associate with existing record just set the foreign key, `attachement_id` in your case |
# |
Nov 6th 2019, 08:24 |
scuadra |
Hello everyone. In Cake 3 is it possible to define the fields to be fetched in belongsTo association in the initialize() method? |
# |
Nov 6th 2019, 08:21 |
conehead |
Still thinks that the created entity is "new". Doesn't seem to recognize the id |
# |
Nov 6th 2019, 08:21 |
conehead |
Good morning |
# |
Nov 6th 2019, 08:20 |
rudy1976s |
good morning to all !!! |
# |
Nov 6th 2019, 08:18 |
conehead |
Hm I'll give it a shot. But it is not a new entity and it works with other `belongs to many` without `associated` as well |
# |
Nov 6th 2019, 08:16 |
dereuromark |
Uppercase first char usually as those are the model names. |
# |
Nov 6th 2019, 08:14 |
karmicdice |
`'associated' => ['attachments']` |
# |
Nov 6th 2019, 08:14 |
karmicdice |
maybe parameter 2 should be `'associated'` ? |
# |
Nov 6th 2019, 08:13 |
conehead |
All I want to do is save an association. It even saves null, when I do ``` $attachment = $this->Attachments->get(1); $post = $this->Posts->newEntity([ 'name' => 'newPost', 'attachment' => $attachment, ]); |
# |
Nov 6th 2019, 08:11 |
karmicdice |
I reckon, it saves a null when you do not add an attachment? For situations like these, have you considered writing a behaviour and utilizing `beforeSave()`. What is the exact scenario and what are you trying to achieve? |
# |
Nov 6th 2019, 08:10 |
conehead |
according to this: https://book.cakephp.org/3/en/orm/saving-data.html#saving-belongsto-associations it should work just fine |
# |
Nov 6th 2019, 08:09 |
slackebot1 |
association. Just says `null`. If I set the `attachment_id` manually in the `posts` table, I can load the data with `contain` just fine. |
# |
Nov 6th 2019, 08:09 |
conehead |
What could be the reason my existing `belongsTo` association is not saved? I have an existing association that works for reading data. When I try ``` $post = $this->Posts->newEntity([ 'name' => 'newPost', 'attachment' => [ 'id' => 1 // my existing attachment ] ]); ``` Always thinks that it is a new attachment instead of using the existing one. Even loading the attachment in a variable and set it explicitly does not save the |
# |
Nov 6th 2019, 07:53 |
kgb.acct.personal |
Don't forget to put `use App\Constant\FileTypes;` |
# |
Nov 6th 2019, 07:53 |
karmicdice |
or outside using what @kgb.acct.personal suggested. |
# |
Nov 6th 2019, 07:52 |
karmicdice |
using self:: |
# |
Nov 6th 2019, 07:52 |
kgb.acct.personal |
FileTypes::IMAGE |
# |
Nov 6th 2019, 07:50 |
markwendelson |
how will i use this constant in my controller? |
# |
Nov 6th 2019, 07:46 |
javier.villanueva |
morning |
# |
Nov 6th 2019, 07:43 |
markwendelson |
good day! |
# |
Nov 6th 2019, 07:07 |
alexdd55976 |
morning |
# |
Nov 6th 2019, 07:04 |
jotpe |
Morning |
# |
Nov 6th 2019, 06:51 |
conehead |
Yeh, was a true pain in the ass. But good to know! |
# |
Nov 6th 2019, 06:49 |
admad |
Cake doesn't have any such "compiled" code |
# |
Nov 6th 2019, 06:42 |
conehead |
Don't need typed properties in core (yet) ;) But absolutely love the idea |
# |
Nov 6th 2019, 06:42 |
conehead |
Had problems once with another framework. Couldn't use type hints because somewhere the code was "compiled", but without the typehints. This resulted in errors |
# |
Nov 6th 2019, 06:19 |
admad |
you can do whatever you want in your app code. Can't add typed properties in 3.x core and it needs to support older php versions |
# |
Nov 6th 2019, 05:58 |
conehead |
Any1 tried cake 3.x with php 7.4 already? Would be so glad to use typed properties |
# |
Nov 6th 2019, 03:13 |
liaogz82 |
any examples I can look up to? |