Db_NoRecordExists and RedBean

When initializing RedBean, I realized that I could simply utilize the Zend_Db resource configured in the application.ini to setup the connection.

require_once APPLICATION_PATH . "/../library/RedBean/redbean.inc.php";
$this->bootstrap("db");
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
R::setup($dbAdapter->getConnection());

This means that I am able to utilize the built in form validation that utilizes the db (Db_NoRecordExists, for example). With one caveat: When there are no tables (cause that’s how RedBean works), attempting to submit a form that persists will cause a SQL exception. I’ll likely export the table structure when I’m pushing to production and won’t have this problem there. It’s merely an annoyance during development.

I’ve enjoyed not writing SQL and simply adding elements to my forms that are then automatically persisted. I’ll obviously need to optimize the table structure once I’ve completed the prototype but that’s an easy thing to do in comparison.