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

  • SEARCH
  • Home
  • 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 8382025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:50:06+00:00 2026-06-09T16:50:06+00:00

Please help with model associations. Schema looks like: translation_typeofs.typeof_id is typeof_[name] foreign key translation_typeofs.typeof_type

  • 0

Please help with model associations.
Schema looks like:
Data model schema

translation_typeofs.typeof_id is typeof_[name] foreign key

translation_typeofs.typeof_type content part of name of relation table (days, colours, buildings or rooms).

TypeofDays model:

class TypeofDay extends AppModel {
    public $name = 'TypeofDay';

    public $hasMany = array(
        'GalleriesTypeofDay' => array(
            'className'  => 'GalleriesTypeofDay',
            'dependent' => true
        ),
        'TranslationTypeof' => array(
            'className'  => 'TranslationTypeof',
            'conditions' => array('TranslationTypeof.typeof_type' => 'days'),
            'dependent' => true
        )
    );
}

TranslationTypeof model:

class TranslationTypeof extends AppModel {
    public $name = 'TranslationTypeof';

    public $belongsTo = array(
        'Language' => array(
            'className'    => 'Language',
            'foreignKey' => 'language_id',
        ),
        'TypeofBuilding' => array(
            'className'  => 'TypeofBuilding',
            'foreignKey' => 'typeof_id',
            'conditions' => array('TranslationTypeof.typeof_type' => 'buildings')
        ),
        'TypeofColour' => array(
            'className'  => 'TypeofColour',
            'foreignKey' => 'typeof_id',
            'conditions' => array('TranslationTypeof.typeof_type' => 'colours')
        ),
        'TypeofRoom' => array(
            'className'  => 'TypeofRoom',
            'foreignKey' => 'typeof_id',
            'conditions' => array('TranslationTypeof.typeof_type' => 'rooms')
        ),
        'TypeofDay' => array(
            'className'  => 'TypeofDay',
            'foreignKey' => 'typeof_id',
            'conditions' => array('TranslationTypeof.typeof_type' => 'days')
        )
    );
}

When I try to save data

$this->TranslationTypeof->saveAll(array(
    'typeof_type'   => $this->data['type_name'],
    'typeof_id'     => $this->data['type_id'],
    'language_id'   => $languageId,
    'text'          => $translation
));

I’m getting error 500 (Internal Server Error)

Error log:

Error: [PDOException] SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (schema.translation_typeofs, CONSTRAINT translation_typeofs_typeof_buildings_fkid1 FOREIGN KEY (typeof_id) REFERENCES typeof_buildings (id) ON DELETE NO ACTION ON UPDATE NO ACTION)

I’m think that it’s something with model association, but can’t find the solution.

  • 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-06-09T16:50:07+00:00Added an answer on June 9, 2026 at 4:50 pm

    As typeof_id is acting as a foreign key depending on the typeof_type provided to it. So there should not be any database foreignKey constraint can be applicable.

    So what you can do is: “Delete the foreignKey constraint from the database using PhpMyAdmin and lets handle it with CakePHP”. Kindly ask if it not worked for you.

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

Sidebar

Related Questions

please help me arrange these 3 buttons horizontally like this photoshopped image: Please take
I have following model: class UserProfile(models.Model): User profile model, cintains a Foreign Key, which
Suppose the following model : class Product include MongoMapper::Document key :name, String key :product_category_id,
I have been frustrated by this for like a day...please help. I have an
Please help me model this in SQLAlchemy. A user can create a question. A
Please see the following Django models: - class Student(models.Model): reference_num = models.CharField(max_length=50, unique=True) name
I get: ImportError: cannot import name Image (from image_blob.py) please help me thanks :s
Please help me somebody to convert unicodestring into string This is how i am
Please help me with this update query. I COMPLETELY understand how redundant this is
please help me. I want know about what types of flags to run an

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.