Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't delete record using schema in Phalcon v4.0 #14080

Closed
Enzo-life opened this issue May 15, 2019 · 7 comments

Comments

@Enzo-life
Copy link

commented May 15, 2019

Just tried to delete a record:

         /** @var Model $className */
         $model = $className::findFirst([
            'id=?0',
            'bind' => [$id],
         ]);
         $model->delete();

Getting error:

Array to string conversion
#0 [internal function]: PDO->prepare('DELETE FROM `Ar...')
#1 [internal function]: Phalcon\Db\Adapter\Pdo->execute('DELETE FROM `Ar...', Array, Array)
#2 [internal function]: Phalcon\Db\Adapter->delete(Array, '`id` = ?', Array, Array)

Checking sources.

/phalcon/mvc/model::delete() has such code:

		let schema = this->getSchema(),
			source = this->getSource();

		if schema {
			let table = [schema, source];
		} else {
			let table = source;
		}

		/**
		 * Join the conditions in the array using an AND operator
		 * Do the deletion
		 */
		let success = writeConnection->delete(table, join(" AND ", conditions), values, bindTypes);

/phalcon/db/adapter::delete() has such code:

public function delete(string table, var whereCondition = null, var placeholders = null, var dataTypes = null) -> bool
	{
		var sql, escapedTable;

		let escapedTable = this->escapeIdentifier(table);

		if !empty whereCondition {
			let sql = "DELETE FROM " . escapedTable . " WHERE " . whereCondition;
		} else {
			let sql = "DELETE FROM " . escapedTable;
		}

Сonclusion: framework doesn't support delete when schema is used.

@JABirchall

This comment has been minimized.

Copy link

commented May 16, 2019

What is $id set too?

@Enzo-life

This comment has been minimized.

Copy link
Author

commented May 16, 2019

$id is integer, the record was fetched from DB successfully.

I'm new in Phalcon and i didn't try to update records yet, but as i see in sources, table value as array with schema and source doesn't process, because table parameter is string in declaration of method delete().

@JABirchall

This comment has been minimized.

Copy link

commented May 16, 2019

jus noticed but might be wrong, but it looks like its the table is Array possibly.

@Enzo-life

This comment has been minimized.

Copy link
Author

commented May 16, 2019

Do you see public function delete(string table, in /phalcon/db/adapter.zep? How can be possible an array there? :)

@JABirchall

This comment has been minimized.

Copy link

commented May 16, 2019

Array to string conversion

@Enzo-life

This comment has been minimized.

Copy link
Author

commented May 16, 2019

Yes, this is a problem.

let table = [schema, source];

////////////////// $table is array
let success = writeConnection->delete(table, join(" AND ", conditions), values, bindTypes);

..............................................

////////////////// $table should be STRING, so it tries to convert given array to string
public function delete(string table, var whereCondition = null, var placeholders = null, var dataTypes = null) -> bool
	{
		var sql, escapedTable;

                ////////////////// $table is already string with value 'Array', as converted, so $escapedTable is string 'Array' too
		let escapedTable = this->escapeIdentifier(table);

                ////////////////// Here we get an SQL 'DELETE FROM `Array` WHERE `id` = ?'
		if !empty whereCondition {
			let sql = "DELETE FROM " . escapedTable . " WHERE " . whereCondition;
		} else {
			let sql = "DELETE FROM " . escapedTable;
		}

P.S. This code was taken from master branch, but in branch 4.0 the same situation.

@niden niden added the Bug - Medium label May 26, 2019

@niden niden added this to To do in 4.1 Release via automation May 26, 2019

@niden niden added 4.0 4.1 and removed 4.1 4.0 labels Jun 21, 2019

@niden niden added 4.0 and removed 4.1 labels Jul 2, 2019

@niden niden added this to To do in 4.0 Release via automation Jul 2, 2019

@niden niden removed this from To do in 4.1 Release Jul 2, 2019

niden added a commit to niden/cphalcon that referenced this issue Jul 4, 2019

niden added a commit to niden/cphalcon that referenced this issue Jul 4, 2019

niden added a commit to niden/cphalcon that referenced this issue Jul 5, 2019

niden added a commit to niden/cphalcon that referenced this issue Jul 5, 2019

niden added a commit to niden/cphalcon that referenced this issue Jul 5, 2019

niden added a commit to niden/cphalcon that referenced this issue Jul 5, 2019

niden added a commit to niden/cphalcon that referenced this issue Jul 5, 2019

niden added a commit to niden/cphalcon that referenced this issue Jul 6, 2019

@niden niden referenced this issue Jul 6, 2019

Merged

T14080 schema delete #14235

4 of 5 tasks complete

@niden niden moved this from To do to In progress in 4.0 Release Jul 6, 2019

niden added a commit that referenced this issue Jul 6, 2019

niden added a commit that referenced this issue Jul 6, 2019

niden added a commit that referenced this issue Jul 6, 2019

@niden

This comment has been minimized.

Copy link
Member

commented Jul 6, 2019

Resolved in #14235

@niden niden closed this Jul 6, 2019

4.0 Release automation moved this from In progress to Done Jul 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
3 participants
You can’t perform that action at this time.