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

Error when updating a model with a POINT type in MySQL #1536

Closed
camcima opened this issue Nov 8, 2013 · 2 comments
Closed

Error when updating a model with a POINT type in MySQL #1536

camcima opened this issue Nov 8, 2013 · 2 comments
Labels
bug A bug report status: medium Medium

Comments

@camcima
Copy link

camcima commented Nov 8, 2013

When you create a table with the POINT data type in MySQL, Phalcon model manager throws an error when you update an instance of the model saying that the POINT field is required.

Steps to reproduce:

SQL Script

CREATE TABLE `robots` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `location` point NOT NULL,
  PRIMARY KEY (`id`)
);

INSERT INTO `robots` (`name`, `location`) VALUES ('Robot 1', GeomFromText('POINT(10 10)'));

PHP Code

<?php

use Phalcon\DI,
    Phalcon\Db\Adapter\Pdo\Mysql as Connection,
    Phalcon\Mvc\Model\Manager as ModelsManager,
    Phalcon\Mvc\Model\Metadata\Memory as MetaData,
    Phalcon\Mvc\Model;

$di = new DI();

//Setup a connection
$di->set('db', new Connection(array(
    "host" => "localhost",
    "username" => "root",
    "password" => "admin",
    "dbname" => "testdb"
)));

//Set a models manager
$di->set('modelsManager', new ModelsManager());

//Use the memory meta-data adapter or other
$di->set('modelsMetadata', new MetaData());

class Robots extends Model
{

}
//Use the model
$robot = Robots::findFirst(1);
$robot->name = 'New Name';
if ($robot->update() == false) {
    foreach ($robot->getMessages() as $message) {
        echo $message;
    }
}

Result

location is required

Note: If you change the data type to GEOMETRY, it works flawlessly.

@dreamsxin
Copy link
Contributor

        if (phalcon_memnstr_str(column_type, SL("int"))) {
                phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE);
                phalcon_array_update_string(&definition, SL("isNumeric"), &PHALCON_GLOBAL(z_true), PH_COPY | PH_SEPARATE);
                phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE);
                break;
            }
$robot = Robots::findFirst(1);      
$robot->name = 'New Name2';
$robot->point = new \Phalcon\Db\RawValue("GeomFromText('POINT(10 10)')");

I will fix it.

This was referenced Nov 11, 2013
phalcon pushed a commit that referenced this issue Nov 11, 2013
phalcon pushed a commit that referenced this issue Nov 11, 2013
@ghost
Copy link

ghost commented Dec 11, 2013

Can this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

3 participants