# |
Jul 1st 2019, 13:47 |
dereuromark |
I had the bug that tags have been saved multiple times, with a count of 1 each. instead of proper reusing. So no, I didnt find another solution, this one works now. |
# |
Jul 1st 2019, 13:46 |
ricksaccous |
that prob won't work for what you're trying to do i suppose |
# |
Jul 1st 2019, 13:46 |
ricksaccous |
@dereuromark save and replace strategy? lol |
# |
Jul 1st 2019, 13:44 |
dereuromark |
admad: the problem is specifically patchEntity and uniqueness only for existing in DB ( https://github.com/dereuromark/cakephp-tags/pull/28/files#diff-33b2925318abc4cc41b83442ae327efbR170 ) it would need to do uniqueness check also on already patched data, not sure if someone already coded sth here. |
# |
Jul 1st 2019, 13:43 |
ndm |
*wouldn't |
# |
Jul 1st 2019, 13:43 |
david |
how would you do this WHERE clause in the CakePHP Way? $newsletter = $this->Newsletters->find() ->where(['MD5(CONCAT("newsletter-", Newsletters.id)) =' => $newsletter_id]) ->first(); |
# |
Jul 1st 2019, 13:43 |
ndm |
@ionas it really depends on what exactly you are trying to do... but you probably would use `IN`, but `ON`, like `JOIN (SELECT ...) AS sub ON sub.id = parent.id` |
# |
Jul 1st 2019, 13:43 |
inoas |
https://gist.github.com/inoas/9195c4526642fd68dc72506e607ac576 |
# |
Jul 1st 2019, 13:42 |
inoas |
because for me it doesnt |
# |
Jul 1st 2019, 13:42 |
inoas |
do you have a very small working snipplet |
# |
Jul 1st 2019, 13:40 |
inoas |
ndm you mean using IN against a subquery within a join? |
# |
Jul 1st 2019, 13:40 |
dereuromark |
admad: that aint working in this case. it creates duplicates. |
# |
Jul 1st 2019, 13:40 |
ndm |
@ionas it should |
# |
Jul 1st 2019, 13:39 |
inoas |
ndm limit in innerjoin should work? |
# |
Jul 1st 2019, 13:35 |
admad |
best it's best to do your stop in beforeMarshal and let normal patching process work |
# |
Jul 1st 2019, 13:34 |
admad |
to avoid having them updated |
# |
Jul 1st 2019, 13:34 |
admad |
might also need to clear dirty fields |
# |
Jul 1st 2019, 13:34 |
dereuromark |
ah, or this: $joinData = $tag->_joinData; $tag = $existing; $tag->_joinData = $joinData; $entity->tags[$k] = $tag; ^^ |
# |
Jul 1st 2019, 13:33 |
admad |
@dereuromark set id field for the entity and set `isNew()` to false :slightly_smiling_face: |
# |
Jul 1st 2019, 13:32 |
mdotobie |
My experience is changes to existing child entities don’t get marked as dirty on the parent entity, only in the child |
# |
Jul 1st 2019, 13:32 |
inoas |
I am a little confused if EXISTS() can help me out |
# |
Jul 1st 2019, 13:31 |
mdotobie |
I think you probably need to patch the entity first, add it to the association and mark it as dirty |
# |
Jul 1st 2019, 13:31 |
mdotobie |
oh so you’re trying to patch the “existing” tag entity and save it with the parent object @dereuromark? |
# |
Jul 1st 2019, 13:30 |
inoas |
ndm join() or innerJoin() / I cannot use innerJoinWith() unless hmmm... add a self join association ? |
# |
Jul 1st 2019, 13:29 |
inoas |
ndm what do you mean / the limit operator? |
# |
Jul 1st 2019, 13:29 |
dereuromark |
i probably need to do some re-patching here though |
# |
Jul 1st 2019, 13:29 |
dereuromark |
i tried $entity->tags[$k] = ['id' => $existingId] + ['_joinData' => $tag->_joinData]; etc |
# |
Jul 1st 2019, 13:29 |
mdotobie |
well I’m assuming a parent object is being saved and a “new” child entity |
# |
Jul 1st 2019, 13:28 |
mdotobie |
can’t you just pass an array with the ID of the existing one to the associated property @dereuromark? |
# |
Jul 1st 2019, 13:27 |
dereuromark |
How can I replace a "new Entity" being saved in a beforeSave with an existing id (entity)? Any quick way? |
# |
Jul 1st 2019, 13:27 |
ndm |
@ionas it works in joins IIRC |
# |
Jul 1st 2019, 13:21 |
ndm |
yep |
# |
Jul 1st 2019, 13:19 |
admad |
@ndm right, so it will be always cast when doing array <=> object conversion |
# |
Jul 1st 2019, 13:18 |
inoas |
with limit 1 |
# |
Jul 1st 2019, 13:18 |
inoas |
instead of column IN (SELECT id FROM... ) |
# |
Jul 1st 2019, 13:18 |
inoas |
wasnt there some other syntax but in... I just need a virtual table, not a join |
# |
Jul 1st 2019, 13:17 |
inoas |
This version of MariaDB doesn't yet support 'LIMIT and IN/ALL/ANY/SOME subquery ... whats your way around? |
# |
Jul 1st 2019, 13:16 |
ndm |
https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts |
# |
Jul 1st 2019, 13:16 |
inoas |
I just hope they introduce another concept of arrays instead of tinkering with those what they are |
# |
Jul 1st 2019, 13:16 |
ndm |
@admad I should have been a little more precise, I ment circumvenving the casting isn't possible anymore... it was possible to do that casting an object to an array, but now the same casting rules apply there |
# |
Jul 1st 2019, 13:16 |
dereuromark |
they sure think things through :P |