Skip to content
This repository

Fix update row #58

Open
wants to merge 1 commit into from

1 participant

Marek Lichtner
Marek Lichtner
  1. This update db and also $application
$application = $software->application[1];
$application["title"] = "Adminer2";
$application->update();
echo $application["title"] // return Adminer2
  1. This update only db but not $application
$application = $software->application[1];
$data = array("title" => "Adminer2");
$application->update($data);
echo $application["title"] // return Adminer 

Second is not consistent and unexpected behavior. This pull request fix second way. I added also test for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 21, 2013
Marek Lichtner lichtner Fix update row d9b85ee
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 24 additions and 0 deletions. Show diff stats Hide diff stats

  1. +4 0 NotORM/Row.php
  2. +20 0 tests/33-update-row.phpt
4 NotORM/Row.php
@@ -98,6 +98,10 @@ function update($data = null) {
98 98 // update is an SQL keyword
99 99 if (!isset($data)) {
100 100 $data = $this->modified;
  101 + } else {
  102 + foreach ($data as $key => $value) {
  103 + $this->offsetSet($key, $value);
  104 + }
101 105 }
102 106 $result = new NotORM_Result($this->result->table, $this->result->notORM);
103 107 return $result->where($this->result->primary, $this[$this->result->primary])->update($data);
20 tests/33-update-row.phpt
... ... @@ -0,0 +1,20 @@
  1 +--TEST--
  2 +Update db and also row
  3 +--FILE--
  4 +<?php
  5 +include_once dirname(__FILE__) . "/connect.inc.php";
  6 +
  7 +$application = $software->application[1];
  8 +$data = array("title" => "Adminer2");
  9 +$application->update($data);
  10 +
  11 +echo "$application[title]\n";
  12 +
  13 +$data = array("title" => "Adminer");
  14 +$application->update($data);
  15 +
  16 +echo "$application[title]\n";
  17 +?>
  18 +--EXPECTF--
  19 +Adminer2
  20 +Adminer

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.