Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Database: Selection::find() renamed to wherePrimary() #953

Merged
merged 1 commit into from

6 participants

@fprochazka

Good idea.

@dg
Owner
dg commented

And what about order() --> orderBy() & orderByDescending()?

@fprochazka

I can't figure out if @dg was ironical :)

@JanTvrdik

@HosipLan: yes, he is :)

@hrach

@HosipLan & @JanTvrdik: Because @dg mentioned sth similar, I'm not sure too. See http://forum.nette.org/cs/7706-api-pro-nette-database-table-selection#p58350.

Situation with order() is quite different. Order accepts FULL (order) expression, so changing to (adding) orderByDescending() would require also complete refactoring, otherwise would be possible:

$selection->orderByDescending('id ASC, name'); 
// ORDER BY id ASC, name DESC

I have nothing against order() -> orderBy().

@dg
Owner
dg commented

No, I am not ironical.

@dg dg merged commit 1a51cb6 into nette:master

1 check passed

Details default The Travis build passed
@vojtech-dobes

There should be return for full BC. Sorry for late review :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 Nette/Database/Table/ActiveRow.php
@@ -183,7 +183,7 @@ public function update($data = NULL)
}
return $this->table->getConnection()
->table($this->table->getName())
- ->find($this->getPrimary())
+ ->wherePrimary($this->getPrimary())
->update($data);
}
@@ -197,7 +197,7 @@ public function delete()
{
$res = $this->table->getConnection()
->table($this->table->getName())
- ->find($this->getPrimary())
+ ->wherePrimary($this->getPrimary())
->delete();
if ($res > 0 && ($signature = $this->getSignature(FALSE))) {
View
17 Nette/Database/Table/Selection.php
@@ -243,7 +243,7 @@ public function getSqlBuilder()
public function get($key)
{
$clone = clone $this;
- return $clone->find($key)->fetch();
+ return $clone->wherePrimary($key)->fetch();
}
@@ -298,11 +298,22 @@ public function select($columns)
/**
- * Selects by primary key.
+ * @deprecated
+ */
+ public function find($key)
+ {
+ trigger_error(__METHOD__ . '() is deprecated; use $selection->wherePrimary() instead.', E_USER_DEPRECATED);
+ $this->wherePrimary($key);
+ }
+
+
+
+ /**
+ * Adds condition for primary key.
* @param mixed
* @return Selection provides a fluent interface
*/
- public function find($key)
+ public function wherePrimary($key)
{
if (is_array($this->primary) && Nette\Utils\Validators::isList($key)) {
foreach ($this->primary as $i => $primary) {
View
8 tests/Nette/Database/Table.cache.phpt
@@ -25,7 +25,7 @@ $connection->setSelectionFactory(new Nette\Database\Table\SelectionFactory(
// Testing Selection caching
-$bookSelection = $connection->table('book')->find(2);
+$bookSelection = $connection->table('book')->wherePrimary(2);
switch ($driverName) {
case 'mysql':
Assert::same('SELECT * FROM `book` WHERE (`id` = ?)', $bookSelection->getSql());
@@ -40,7 +40,7 @@ $book = $bookSelection->fetch();
$book->title;
$book->translator;
$bookSelection->__destruct();
-$bookSelection = $connection->table('book')->find(2);
+$bookSelection = $connection->table('book')->wherePrimary(2);
switch ($driverName) {
case 'mysql':
Assert::same('SELECT `id`, `title`, `translator_id` FROM `book` WHERE (`id` = ?)', $bookSelection->getSql());
@@ -63,7 +63,7 @@ switch ($driverName) {
}
$bookSelection->__destruct();
-$bookSelection = $connection->table('book')->find(2);
+$bookSelection = $connection->table('book')->wherePrimary(2);
switch ($driverName) {
case 'mysql':
Assert::same('SELECT `id`, `title`, `translator_id`, `author_id` FROM `book` WHERE (`id` = ?)', $bookSelection->getSql());
@@ -142,7 +142,7 @@ foreach ($connection->table('author') as $author) {
foreach ($relatedStack as $related) {
$property = $related->reflection->getProperty('accessedColumns');
- $property->setAccessible(true);
+ $property->setAccessible(TRUE);
// checks if instances have shared data of accessed columns
Assert::same(array('id', 'author_id'), array_keys((array) $property->getValue($related)));
}
View
2  tests/Nette/Database/Table.delete().phpt
@@ -31,4 +31,4 @@ Assert::same(3, $count);
$book->delete(); // DELETE FROM `book` WHERE (`id` = ?)
-Assert::same(0, count($connection->table('book')->find(3))); // SELECT * FROM `book` WHERE (`id` = ?)
+Assert::same(0, count($connection->table('book')->wherePrimary(3))); // SELECT * FROM `book` WHERE (`id` = ?)
Something went wrong with that request. Please try again.