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

model->findFirstBy... doesn't work with columnMap() in Oracle #10490

Closed
skaosYan opened this issue Jun 9, 2015 · 7 comments
Closed

model->findFirstBy... doesn't work with columnMap() in Oracle #10490

skaosYan opened this issue Jun 9, 2015 · 7 comments

Comments

@skaosYan
Copy link

skaosYan commented Jun 9, 2015

Hi,

Phalcon 2.0.2, Oracle 12c.

I have set columnMap() for my model.
Then, I invoke find on my model like this:
Users::findFirstByEmail('[email protected]');

In SQL debug.log I see:

[Tue, 09 Jun 15 02:58:38 +0300][INFO] SELECT COUNT() "numrows" FROM (SELECT * FROM (SELECT Z1., ROWNUM PHALCON_RN FROM (SELECT USERS.USERID, USERS.NAME, USERS.EMAIL, USERS.PASSWORD, USERS.MUSTCHANGEPASSWORD, USERS.PROFILESID, USERS.SEX, USERS.PHONE, USERS.BIRTHDATE FROM USERS WHERE USERS.EMAIL = :0) Z1 WHERE ROWNUM <= 1))

But the call itself results in error:

Column 'PHALCON_RN' doesn't make part of the column map
#0 [internal function]: Phalcon\Mvc\Model::cloneResultMap(Object(Vokuro\Models\Users), Array, Array, 0, false)

#1 [internal function]: Phalcon\Mvc\Model\Resultset\Simple->current()

#2 [internal function]: Phalcon\Mvc\Model\Resultset->getFirst()

#3 [internal function]: Phalcon\Mvc\Model\Query->execute(Array, NULL)

#4 [internal function]: Phalcon\Mvc\Model::findFirst(Array)

#5 /home/var/www/html/v1/app/controllers/UsersController.php(93): Phalcon\Mvc\Model::__callStatic('findFirstByEmai...', Array)

#6 /home/var/www/html/v1/app/controllers/UsersController.php(93): Vokuro\Models\Users::findFirstByEmail('[email protected]')

#7 [internal function]: Vokuro\Controllers\UsersController->createAction()

#8 [internal function]: Phalcon\Dispatcher->dispatch()

#9 /home/var/www/html/v1/public/index.php(41): Phalcon\Mvc\Application->handle()

How this bug can be fixed?

@dreamsxin
Copy link
Contributor

Please submit model code?

@skaosYan
Copy link
Author

skaosYan commented Jun 9, 2015

I have fixed it by adding 'PHALCON_RN' => 'phalcon_rn', into the columnMap(). But this should be done at core level.

getDI()->get('db')->lastInsertId($this->getSequenceName()); } public function getSource() { return "USERS"; } public function columnMap() { return array( 'USERID' => 'userid', 'NAME' => 'name', 'PHONE' => 'phone', 'EMAIL' => 'email', 'PASSWORD' => 'password', 'MUSTCHANGEPASSWORD' => 'mustChangePassword', 'PROFILESID' => 'profilesId', 'SEX' => 'sex', 'BIRTHDATE' => 'birthdate', 'PHALCON_RN' => 'phalcon_rn', ); } public function initialize() { $this->skipAttributesOnCreate( array('USERID') ); } }

@dreamsxin
Copy link
Contributor

Fields should case sensitive.

@skaosYan
Copy link
Author

skaosYan commented Jun 9, 2015

Sorry, I do not understand how to apply your answer, would you elaborate?

@dreamsxin
Copy link
Contributor

Column name is phalcon_rn, Use uppercase PHALCON_RN must be map.

@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]);

@skaosYan
Copy link
Author

Cool, thank you

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

3 participants