cakephp Model validation error message not displaying in hasOne association

后端 未结 2 602
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 20:57

i want to do model validation with association in a single form. i have two tables users(parent table) and user_details(child

2条回答
  •  孤独总比滥情好
    2021-01-21 21:47

    validation working for only users table because i have created newEntity for users table only.

    That has nothing to do with it. The problem is that you are not following the naming conventions properly.

    Filenames must match classnames, so it's UserDetailsTable.php, not UserDetails.php, UsersTable.php, not usersTable.php, etc.

    And the correct property name for a hasOne association, is the singular, underscored variant of the association name, so for UserDetails that would be user_detail, consequently the name for the related form control should be user_detail.name.

    See also

    • Cookbook > CakePHP at a Glance > CakePHP Conventions > File and Class Name Conventions
    • Cookbook > Views > Helpers > Form > Creating Inputs for Associated Data
    • Cookbook > Database Access & ORM > Saving Data > Saving HasOne Associations
    • Cookbook > Database Access & ORM > Associations - Linking Tables Together > HasOne Associations

提交回复
热议问题