Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

Zend Framework: Zend_Validate_Db_RecordExists
Zend_Validate_Db_NoRecordExists Component Proposal

Proposed Component Name Zend_Validate_Db_RecordExists
Zend_Validate_Db_NoRecordExists
Developer Notes http://framework.zend.com/wiki/display/ZFDEV/Zend_Validate_Db_RecordExists
Zend_Validate_Db_NoRecordExists
Proposers Ryan Mauger
Zend Liaison Ralph Schindler
Revision 1.0 - 10 October 2008: Initial Draft.
1.1 - 10 October 2008: Revised class skeleton to use fetchRow and limit(1) after discussion with Shane Lilge (Toppy).
1.2 - 11 October 2008: Revised class skeleton after discussion with Ben Scholzen (DASPRiD) and Robin Skoglund (robinsk).
1.3 - 26 November 2008: Revised class skeletons, added utility table.
1.4 - Added Abstract class. (wiki revision: 37)

Table of Contents

1. Overview

The process of checking user input against a database to check for the presence or absence of a matching record is pretty common place.
This process currently will end up either in your model or controller, when it should in fact be in the validation of your form.
The usage of these validators will negate the need to perform a validity check against a form, pass that to the controller, check it against the model, and then pass it back to the user with the appropriate feedback.

This will also simplify the process of providing user feedback.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

  • Zend_Validate_Db_RecordExists will confirm a record exists in a table
  • Zend_Validate_Db_NoRecordExists will confirm a record does not exist in a table
  • Both components will allow a single record to be excluded, or a sql string to be added as a where clause to exclude records from the select.
  • ZF-3486 Should be resolved, to allow the decision whether to drop the class Zend_Validate_Db_Table to be made.

4. Dependencies on Other Framework Components

  • Zend_Validate_Abstract
  • Zend_Db_Table_Abstract
  • Zend_Db_Table_Adapter

5. Theory of Operation

An abstract class provides initialisation for two classes. An instance of Zend_Db_Table will be created to fetch the adapter to use for queries.
The abstract class will also provide a method to build the query.
If a sql where clause or an array containing field and value keys is given, a record may be omitted from the query.

6. Milestones / Tasks

  • Milestone 1: design notes will be published here
  • Milestone 2: Working prototype checked into the incubator supporting use cases #1
  • Milestone 3: Unit tests exist, work, and are checked into SVN.
  • Milestone 4: Initial documentation exists.

7. Class Index

  • Zend_Validate_Db_Abstract
  • Zend_Validate_Db_RecordExists
  • Zend_Validate_Db_NoRecordExists
  • Zend_Validate_Db_Table

8. Use Cases

UC-01
UC-02

9. Class Skeletons

Abstract.php

RecordExists.php

NoRecordExists.php

Table.php

]]></ac:plain-text-body></ac:macro>

]]></ac:plain-text-body></ac:macro>

Labels:
proposal proposal Delete
validate validate Delete
database database Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Oct 10, 2008

    <p>Would have liked to have had this on my last couple of projects. Would have saved some time and added clarity in several places. Very handy. I'll definitely use this in upcoming projects and would like to see it in ZF.</p>

  2. Jan 09, 2009

    <ac:macro ac:name="note"><ac:parameter ac:name="title">Official Zend Response</ac:parameter><ac:rich-text-body>

    <p>This component is accepted to the <strong>Standard Incubator</strong>.</p>

    <p>One area we'd like to see improve is the removal of the Zend_Validate_Db_Table class. If the goal is to be able to get a default adapter, Zend_Db_Table_Abstract::getDefaultAdapter() === null should suffice in that respect. If you have any additional comments on that one concern, by all means, please address them with me either here, mail or IRC.</p>

    <p>-ralph</p>
    </ac:rich-text-body></ac:macro>

  3. Jan 15, 2009

    <p>Excellent addition! </p>

  4. Mar 18, 2009

    <p>Ryan, do you plan to have this ready for the 1.8 release? Please let me know by replying here.</p>

    1. Mar 19, 2009

      <p>Wil, Yes. I believe I just have to finish the unit tests and write the documentation. I will try and get those done some time in the next week.<br />
      Is there a date for the 1.8 release yet?</p>

  5. Mar 31, 2009

    <p>Tests and documentation are now in incubator.</p>