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

Unique validation fails: Column 'ROWCOUNT' doesn't make part of the column map #10532

Closed
skaosYan opened this issue Jun 22, 2015 · 1 comment
Closed

Comments

@skaosYan
Copy link

Hi,

I have Phalcon 2.0.2 on Oracle 12c. Unique validation for a model fails with error.
Adding of ROWCOUNT into a column map doesn't help. How to fix this error?

Column 'ROWCOUNT' doesn't make part of the column map<br>#0 [internal function]: Phalcon\Mvc\Model::cloneResultMap(Object(Phalcon\Mvc\Model\Row), Array, Array, 0, false)<br />
#1 [internal function]: Phalcon\Mvc\Model\Resultset\Simple-&gt;current()<br />
#2 [internal function]: Phalcon\Mvc\Model\Resultset-&gt;getFirst()<br />
#3 [internal function]: Phalcon\Mvc\Model::_groupResult('COUNT', 'rowcount', Array)<br />
#4 [internal function]: Phalcon\Mvc\Model::count(Array)<br />
#5 [internal function]: Phalcon\Mvc\Model\Validator\Uniqueness-&gt;validate(Object(Vokuro\Models\UserCompany))<br />
#6 /home/var/www/html/v1/app/models/UserCompany.php(40): Phalcon\Mvc\Model-&gt;validate(Object(Phalcon\Mvc\Model\Validator\Uniqueness))<br />
#7 [internal function]: Vokuro\Models\UserCompany-&gt;validation()<br />
#8 [internal function]: Phalcon\Mvc\Model-&gt;fireEventCancel('validation')<br />
#9 [internal function]: Phalcon\Mvc\Model-&gt;_preSave(Object(Phalcon\Mvc\Model\MetaData\Memory), false, false)<br />
#10 /home/var/www/html/v1/app/controllers/UserController.php(144): Phalcon\Mvc\Model-&gt;save()<br />
#11 [internal function]: Vokuro\Controllers\UserController-&gt;addCompanyAction('155', '1')<br />
#12 [internal function]: Phalcon\Dispatcher-&gt;dispatch()<br />
#13 /home/var/www/html/v1/public/index.php(43): Phalcon\Mvc\Application-&gt;handle()<br />
#14 {main}

SQL log contains:

15 08:04:51 +0300][INFO] SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_TABLES WHERE TABLE_NAME='USER_COMPANY'
[Mon, 22 Jun 15 08:04:51 +0300][INFO] SELECT TC.COLUMN_NAME, TC.DATA_TYPE, TC.DATA_LENGTH, TC.DATA_PRECISION, TC.DATA_SCALE, TC.NULLABLE, C.CONSTRAINT_TYPE, TC.DATA_DEFAULT, CC.POSITION FROM ALL_TAB_COLUMNS TC LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P')) ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME WHERE TC.TABLE_NAME = 'USER_COMPANY' ORDER BY TC.COLUMN_ID
[Mon, 22 Jun 15 08:04:51 +0300][INFO] SELECT COUNT(42) AS rowcount FROM USER_COMPANY WHERE USER_COMPANY.USERID = :0 AND USER_COMPANY.COMPANYID = :1
[Mon, 22 Jun 15 08:04:51 +0300][INFO] SELECT COUNT(*) "numrows" FROM (SELECT COUNT(42) AS rowcount FROM USER_COMPANY WHERE USER_COMPANY.USERID = :0 AND USER_COMPANY.COMPANYID = :1)

My model:

<?php
namespace Vokuro\Models;

use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Validator\Uniqueness;
use Phalcon\Mvc\Model\MetaData;
use Phalcon\Db\Column;
use Phalcon\Mvc\Model\Message;


class UserCompany extends BaseModel
{
    public $userCompanyId;
    public $userId;
    public $companyId;
    public $userCompanyStatus;

    public function getSource()
    {
        return "USER_COMPANY";
    }

    public function columnMap()
    {
        return array(
            'USERCOMPANYID'  => 'userCompanyId',
            'COMPANYID'  => 'companyId',
            'USERID'    => 'userId',
        'DATE_ADDED' => 'dateAdded',
        'USER_COMPANY_STATUS' => 'userCompanyStatus',
        'PHALCON_RN' => 'phalcon_rn',
        );
    }

    public function validation()
    {

    $this->validate(new Uniqueness(array(
          'field' => array('userId', 'companyId')
    )));

    if ($this->validationHasFailed() == true) {
            $message = new Message("Юзер уже добавил эту компанию!");
        $this->appendMessage($message);
        return false;
    }
    }

    public function initialize() {                        
        $this->skipAttributesOnCreate(array('DATE_ADDED','USER_COMPANY_STATUS'));

        $this->belongsTo("userId", 'Vokuro\Models\Users', "userId", array('alias' => 'User'));
        $this->belongsTo("companyId", 'Vokuro\Models\Company', "companyId", array('alias' => 'Company'));

        $this->hasMany('userCompanyId', 'Vokuro\Models\UserCompanyDiscount', 'userCompanyId', array(
            'alias' => 'UserCompanyDiscounts'
        )); 
    }
}
@andresgutierrez
Copy link
Contributor

This is fixed in the 2.0.x branch (Phalcon 2.0.4), you have to change a global ORM setting to allow unexpected columns:

\Phalcon\Mvc\Model::setup(['ignoreUnknownColumns' => true]);

niden added a commit that referenced this issue Nov 4, 2018
…om/niden/cphalcon into niden-T10532-case-insensitive-column-map

* 'T10532-case-insensitive-column-map' of https://github.com/niden/cphalcon:
  [#10532] - Corrected variable
  [#10532] - Updated changelog
  [#10532] - Added case insensitive column map in model
niden added a commit that referenced this issue Nov 4, 2018
* niden-T10532-case-insensitive-column-map:
  [#10532] - Corrected variable
  [#10532] - Updated changelog
  [#10532] - Added case insensitive column map in model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants