Skip to content

save() fails silently if you have select()ed some fields, but not the id #203

@ghost

Description

Given the following table

CREATE TABLE `users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `email` varchar(254) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

With the data

INSERT INTO `users` (`id`, `email`)
VALUES ('1', '[email protected]');

And the following code

$user = ORM::for_table('users')
    ->where('id', 1)
    ->select('email')
    ->find_one()
;

$user->email = '[email protected]';

$success = $user->save();

$success is true, but the database will not have reflected this change (email will still be [email protected]).

get_last_query() indicates that the following query is being executed

UPDATE `users` SET `email` = '[email protected]' WHERE `id` = ''

Notice that it could not find the id value to place in the query.

A work around is to remove the select() call altogether, or at least call select('id'), but I still think this is a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions