Michael Miller Fri Jul 16 02:37:58 -0400 2010

Subject: Foreign key validation?


I have several foreign key constraints in my database, and I was wondering if there was a technique or standard way for validating them within php.activerecord.

From the list:

I am not exactly looking for something this strong:
(as I understand it, this would run the validators of the associated objects, I merely wish to detect the presence or lack thereof)


Kien La Fri Jul 16 21:13:53 -0400 2010

Try the following:

static $validates_presence_of = array(

Michael Miller Tue Jul 20 05:29:38 -0400 2010

Well, sure, but I was worried more along the lines of:

id: 1 name: Jim Writerson

id: 2 author_id: 1 name: PHP-Activerecord Makes PHP Fun!

$a = Author::find(1);
(You shouldn't be able to delete an association because a Book is referring to it! Perhaps even given the option to delete 'force'=>true where it breaks the link, and delete 'associated' => true deletes any books that belong_to it)

Thanks to line 877 of http://github.com/kla/php-activerecord/blob/master/lib/Model.php
if (!$this->invoke_callback('before_destroy',false))

It seems reasonable that I could write a before-callback that interrupts the process.