Yii Framework Forum: [SOLVED]CH8 - RBAC test fails on page 199 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[SOLVED]CH8 - RBAC test fails on page 199

#1 User is offline   yiiter 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 03-January 11

Posted 13 January 2011 - 09:33 PM

1) ProjectTest::testDelete
CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`trackstar_test`.`tbl_project_user_role`, CONSTRAINT `tbl_project_user_role_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `tbl_project` (`id`))

C:\inetpub\wwwroot\Yii 1.1.5\framework\db\CDbCommand.php:256
C:\inetpub\wwwroot\Yii 1.1.5\framework\db\ar\CActiveRecord.php:1647
C:\inetpub\wwwroot\Yii 1.1.5\framework\db\ar\CActiveRecord.php:1113
C:\inetpub\wwwroot\Yii 1.1.5\trackstar\protected\tests\unit\ProjectTest.php:75

FAILURES!
Tests: 7, Assertions: 14, Errors: 1.


On page 199, at the top of the page when I modify the testIsInRole() function I am getting the above error when I run the ProjectTest.php.

ProjectTest.php line 75 refers to this code:
 $this->assertTrue($project->delete()); 


All my tests ran flawlessly up until this point, can someone give me a pointer as to what I might be doing wrong here?
0

#2 User is offline   jefftulsa 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 168
  • Joined: 06-October 08
  • Location:Austin, TX

Posted 13 January 2011 - 10:17 PM

The foreign keys defined on the db on which these were tested have the following cascading definitions:

ON DELETE CASCADE ON UPDATE CASCADE;


Without this configured in your schema, then the delete would need to be altered to explicitly delete related content before deleting the primary row to which the other data is related.

The book is making an attempt to be database agnostic, and glosses over some of the schema specific details. The download-able code has the full MySQL schema with these definitions in-place.
0

#3 User is offline   yiiter 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 03-January 11

Posted 13 January 2011 - 10:55 PM

View Postjefftulsa, on 13 January 2011 - 10:17 PM, said:

The foreign keys defined on the db on which these were tested have the following cascading definitions:

ON DELETE CASCADE ON UPDATE CASCADE;


Without this configured in your schema, then the delete would need to be altered to explicitly delete related content before deleting the primary row to which the other data is related.

The book is making an attempt to be database agnostic, and glosses over some of the schema specific details. The download-able code has the full MySQL schema with these definitions in-place.


I cannot believe I overlooked the fact that FK constraints were not in my DDL file. What's more embarrassing is that the plain English mySQL error in my face!!!

Thank you very much for this great resource Jeff. This is my first attempt to learn a framework and I'm really enjoying this experience though I might have to go through one more time. And the lack of sleep and caffeine is definitely not helping that's for sure...

Best,
0

#4 User is offline   pablobablo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 02-December 11

Posted 27 December 2011 - 06:19 PM

Right DDL:
create table tbl_project_user_role
(
	project_id INTEGER NOT NULL,
	user_id INTEGER NOT NULL,
	role VARCHAR(64) NOT NULL,
	primary key (project_id, user_id,role),
	foreign key (project_id) references tbl_project (id) ON DELETE CASCADE ON UPDATE CASCADE,
	foreign key (user_id) references tbl_user (id) ON DELETE CASCADE ON UPDATE CASCADE,
	foreign key (role) references AuthItem (name) ON DELETE CASCADE ON UPDATE CASCADE
);

0

#5 User is offline   Joemaxwell 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 13-February 13
  • Location:Fiji Via Melbourne

Posted 11 April 2013 - 12:46 AM

How Do configure this please help?

View Postjefftulsa, on 13 January 2011 - 10:17 PM, said:

The foreign keys defined on the db on which these were tested have the following cascading definitions:

ON DELETE CASCADE ON UPDATE CASCADE;


Without this configured in your schema, then the delete would need to be altered to explicitly delete related content before deleting the primary row to which the other data is related.

The book is making an attempt to be database agnostic, and glosses over some of the schema specific details. The download-able code has the full MySQL schema with these definitions in-place.

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users