Jump to content
Larry Ullman's Book Forums

Strange Problem - Exist Fails - Only If Table Empty


matthuisman
 Share

Recommended Posts

Hi,

 

Having a strange issue working through the Yii book CMS example.

 

So. I will empty all tables then login as admin.

I can then add a new user fine. user_id = 1.

 

If I then try to add a page/comment/file, and input a user_id of 1, it returns "User "1" is invalid."

The 'exist' validation is failing even though there is a user with user_id of 1.

 

Strangely, this only happens if there are no rows in the 'page' table.

If i manually add a row to the 'page' table then I can add pages from then on not a problem.

But, if I go and delete the pages and then try add a page - error comes back.

 

So, the fault only happens if the table is empty.

 

Any help would be apperciated.

 

Thanks,

 

Matt

Link to comment
Share on other sites

Update:

Fixed the issue by using:

array('user_id', 'exist', 'attributeName'=>'id', 'className'=>'User'),

 

Did a bit of debugging, the SQL yii was using before using the above was

"SELECT 1 FROM `page` `t` WHERE `t`.`user_id`=:ycp0 LIMIT 1"

 

Now, with the above it uses

"SELECT 1 FROM `user` `t` WHERE `t`.`id`=:ycp0 LIMIT 1"

 

So, think this may be a mistake in the book?

 

Thanks,

 

Matt

Link to comment
Share on other sites

  • 3 months later...

I didn't have this problem while I was writing that section, but I'll check into it. An issue is that the CMS example is used for various demonstration purposes, so it's not a complete thing (until I do that in Part 4 of the book), which can lead to problems depending upon what you have or have not implemented.

Link to comment
Share on other sites

 Share

×
×
  • Create New...