Log message #4212451

# At Username Text
# Nov 6th 2019, 10:25 javier.villanueva away_team_id
# Nov 6th 2019, 10:25 javier.villanueva home_team_id
# Nov 6th 2019, 10:23 dev.cyrusjayson I have Matches model and it has two fields coming from Teams model. so the Matches model has this ``` Teams id *Matches* team_1 <team id> FK team_2 <team id> FK ``` what is the proper way?
# Nov 6th 2019, 10:16 javier.villanueva In other hand my other option is to have one entity Reports and related with model with A fields, model with B fields, model with C fields....
# Nov 6th 2019, 10:12 javier.villanueva Hi... if anyone can advise me. I have the next structure Reports (Reports A with any fields, Reports B with other fields, Reports C...). My doubt is if I create one entity for each type of Report (cause fields are very differents), different tables for each report type, etc. Its important that this Reports have a relationship with a Workorder [hasMany Reports].
# Nov 6th 2019, 09:22 markwendelson add parent::initialize(); solves the problem
# Nov 6th 2019, 09:08 markwendelson getting error when doing this in a controller
# Nov 6th 2019, 08:58 pidlo ok i get this $query->newExpr('DATE_ADD(dfrom, INTERVAL - @num MONTH)')
# Nov 6th 2019, 08:50 kgb.acct.personal It's not that inconvenient to be honest.
# Nov 6th 2019, 08:48 conehead That might be true. Not as convinient as it could be :P
# 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