Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Major ORM bug or not?

This code:

    $booking = Booking::findFirst(3278);
    $booking->BookingStatus = Booking::STATUS_CANCELLED;
    $booking->update();

Produce this sql:

UPDATE `Booking` SET `QrCode` = '', `isOnSchedule` = 0 WHERE `Id` = 3278 AND `Route` = 2 AND `UBR` = 'UBR-58974' AND `CreatedAt` = '2014-06-13 21:22:35' AND `SlotTime` = '11:00' AND `FlightDate` = '2014-08-02' AND `BookingStatus` = '0'

That is totaly wrong!!!! Who this can be?

1) Why QrCode and isOnSchedule is updated?

2) Why BookingStatus is not updated?

I notice this problem on several ocasions. Booking table have one foreign key. I noticed that all tbales with forwign keys have same problem. This is big issue.



7.2k
edited Aug '14

work code

        $discuss = Discussions::findFirst(3);
        $newTitle = $discuss->getTitle() . ' new';
        $discuss->setTitle($newTitle);
        $discuss->update();
        $discuss = Discussions::findFirst(3);
        var_dump($discuss->toArray());

sql log

[Wed, 27 Aug 14 21:17:52 +0300][INFO] SELECT `discussions`.`id`, `discussions`.`title`, `discussions`.`topic`, `discussions`.`categories_id`, `discussions`.`users_id`, `discussions`.`created_at`, `discussions`.`slug` FROM `discussions` WHERE `discussions`.`id` = 3 LIMIT :1
[Wed, 27 Aug 14 21:17:52 +0300][INFO] UPDATE `discussions` SET `title` = ?, `topic` = ?, `categories_id` = ?, `users_id` = ?, `created_at` = ?, `slug` = ? WHERE `id` = ?
[Wed, 27 Aug 14 21:17:52 +0300][INFO] SELECT `discussions`.`id`, `discussions`.`title`, `discussions`.`topic`, `discussions`.`categories_id`, `discussions`.`users_id`, `discussions`.`created_at`, `discussions`.`slug` FROM `discussions` WHERE `discussions`.`id` = 3 LIMIT :1

output

array(7) { ["id"]=> string(1) "3" ["title"]=> string(17) "Discussions 3 new" ["topic"]=> string(22) "Topic of discussions 3" ["categories_id"]=> string(1) "2" ["users_id"]=> string(1) "7" ["created_at"]=> string(10) "1409163472" ["slug"]=> string(17) "discussions_3_new" }

Code of model Discusiions you can find at https://github.com/oleg578/PhalconForumSample/blob/master/Apps/Models/Discussions.php

P.S. You don't need foreign key usually. See MySQL documentation. And check your foreign keys, or delete it :)



4.5k
edited Aug '14

I do not see how this answers my question?

This is working but I do no want to use sql:

    $this->db->update(
        "Booking",
        array("BookingStatus"),
        array("0"),
        "Id=".$id
   );

P.S. You don't need foreign key usually. See MySQL documentation. And check your foreign keys, or delete it :)

Really? I pretend that i did not hear this.



7.2k
edited Aug '14

What storage engine are you use?

I don't undestand. If you want change any properites of object (result of find) - you can use this object with new properties only in life circle of application ( in one request). Then you can't use update. If you want update row in table - you have to update row...



4.5k

What do you mean by:

you can use this object with new properties only in life circle of application ( in one request). Then you can't use update.

I use innodb.

What storage engine are you use?



83.4k

Are Id, Route, UBR, CreatedAt, SlotTime, FlightDate, and BookingStatus marked as primary keys?



4.5k

Are Id, Route, UBR, CreatedAt, SlotTime, FlightDate, and BookingStatus marked as primary keys?

YES



83.4k
Accepted
answer

THAT'S WHY



4.5k
edited Aug '14

THis mysql work banch is so stupid. I did not release that mysql workbanch will export indexes as composite keys.

Thank you Phalcon.