Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6091277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:18:33+00:00 2026-05-23T12:18:33+00:00

I have two models: Bar HABTM Foo. Now I have bars_foos join table with

  • 0

I have two models: Bar HABTM Foo. Now I have bars_foos join table with some additional fields.

When I add new Bar with some Foo associations or vice versa, I need to run many validation checks, whether the new associations are kosher. Checks are based on the additional fields defined and already saved associations.

Where should I run these validations? In Bar/Foo controller? Or should I create BarsFoo model with validation rules?

When I keep HABTM relationship to get all the auto-magic from Cake, I cannot find a way to tell Cake to use my own predefined BarsFoo model with validations rules. Cake creates its own virtual model and ignores mine.

Or should I (in this specific case) break HABTM into hasMany-belongsTo-hasMany relationship, where I can use my own BarsFoo model?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:18:33+00:00Added an answer on May 23, 2026 at 12:18 pm

    You can define your join model using the with key and create your validations there:

    public $hasAndBelongsToMany = array(
        'Bar' => array(
            …
            'with' => 'BarFoos'
        )
    );
    

    http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models: class Foo(models.Model): foo_field = ... class Bar(models.Model): foo = models.ForeignKey(Foo,
I have two models, Foo and Bar . Bar has a foreign key to
I have two models, Foo and Bar, with same attributes, and I'm 'caching' user
Given two model classes, Foo and Bar , I want Foo to have 3
I have two models, user and group. I also have a joining table groups_users.
I have two models that has a manytomany relationship with a 'through' table in
I have two entities Foo and Bar with a Many to Many relationship between
I have two classes, Foo and Bar, in a Django app (on AppEngine if
Let's say my app has two models, Foo and Bar. Foo optionally belongs_to Bar.
I have models foo, bar, and baz like so # has a field join_condition_string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.