#5997: Validation HABTM
---------------------------------+------------------------------------------
    Reporter:  tek01             |          Type:  Enhancement
      Status:  new               |      Priority:  Medium     
   Milestone:  1.2.x.x           |     Component:  Validation 
     Version:  1.2 Final         |      Severity:  Trivial    
    Keywords:  validation habtm  |   Php_version:  PHP 5      
Cake_version:  1.2.0.7962        |  
---------------------------------+------------------------------------------
 I have some doubt about habtm validation. Let's start with an example: if
 you specify a Post belongsTo Category you have your category_id field in
 your posts table and a select field in the add action of posts
 controller.[[BR]]
 [[BR]]


 If you want to check that at least one category is selected when creating
 a new post you simply add a validation rule in post model: something like
 $validate = array('category_id' => 'notEmpty') (or something like
 that).[[BR]]
 [[BR]]


 But what if you have and HABTM relation between the two models? So Post
 hasAndBelongsToMany Category , you still have your add form with a
 multiple select (Category.Category), right? but then it seems you have no
 chance to set a validation rule in your post model to check that at least
 one category have been selected.[[BR]]
 [[BR]]


 Yeah, sure. There is some workarounds. You can use beforeValidate in your
 Post model, or you can set a validation rule in your category model and
 then do some tricky things in posts controller (like set data in
 $this->Category, call its validation method and if it returns true proceed
 with post saving), but i don't think that is the best way to get the job
 done.[[BR]]
 [[BR]]


 I think it would be a great enhancement being able to tell cake that it
 has to validate an habtm field simply by specifying it in the $validate
 array.[[BR]]
 [[BR]]


 Sorry for my english.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/5997>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to