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 8725811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:07:20+00:00 2026-06-13T08:07:20+00:00

I have hasMany relation between Employee and Schedule. When editing an Employee, I manage

  • 0

I have hasMany relation between Employee and Schedule.
When editing an Employee, I manage to get the current schedule and populate my form.

Upon saving, I use:

        if ($this->Employee->save($this->request->data)) {
            $this->Employee->Schedule->save($this->request->data, $validate = false);
            ....
        }

Employee data saves fine, but Schedule record is left untouched.

I’m actually providing the id as part as the array. On my controller, debug($this->request->data) shows:

array(
'Employee' => array(
    'emp_position' => '1',
    'name' => 'the name',
    'emp_gender' => '1',
    'emp_father' => '',
    'emp_mother' => '',
    'emp_dob' => 'October 13, 1964',
    ...
    ..
),
'Schedule' => array(
    (int) 0 => array(
        'id' => '7',
        'ho_lu2' => '10:00',
        'ho_ma2' => '01:00',
        'ho_mi2' => '00:00',
        'ho_ju2' => '00:00',
        'ho_vi2' => '00:00',    
        'ho_do4' => '00:00'
    )
)
)           

.

***************** Update ************

I think it has to do with foreign keys being different on my two tables

My employees table:

CREATE TABLE IF NOT EXISTS `employees` (
  `id` int(5) DEFAULT NULL,
  `emp_appserial` int(5) unsigned NOT NULL AUTO_INCREMENT,
  ...

(Please note that on Employee table, emp_appserial is my pk autoincr, and employee_id can be null for some records)

My Schedules table:

CREATE TABLE IF NOT EXISTS `schedules` (
  `id` int(5) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  `employee_id` int(5) unsigned NOT NULL,
  ...

Since I’ve linked these tables using a different field, i use foreignKey:

On my model, I linked:
Employee Model:

        var $hasMany = array(
            'Schedule' => array(
                'foreignKey' => 'employee_id',  //(field on Schedule)
                'dependent' => true
            )
        );

        public $primaryKey = 'emp_appserial'            

Schedule Model:

var $belongsTo = array('Employee',
    'Employee' => array(
        'foreignKey' => 'emp_appserial'    //(field on Employee)
    )
);

My posted data now includes employee_id for Schedule, and emp_appserial for Employee

array(
'Employee' => array(
    'id' => null,
    'emp_appserial' => '119'
    ...
),
'Schedule' => array(
    (int) 0 => array(
        'id' => '6',
        'name' => 'segundo horario',
        'emp_appserial' => '119',   
        'employee_id' => '119'
    )
)
)           

(tried appending to Schedule both id and serial to try my luck- not good.)

Any help greatly appreciated.

Thanks a lot !

  • 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-13T08:07:22+00:00Added an answer on June 13, 2026 at 8:07 am

    “As a rule, when working with hasOne, hasMany, and belongsTo associations, its all about keying” – CakePHP Manual.

    Your Employee array has to pass an id and the schedule array needs to have an employee_id so cake knows what are the linked models.

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

Sidebar

Related Questions

i have this form that saves the relation between 2 tables in my db
I have a many-to-many relation between users and the channels they subscribe to. But
I have database relation as follows between question table and Hardware detail table .
I have a quite complicated relation between models and are now frustrated by a
I have a domain class called Order and that class has hasMany relation with
I am trying to get a One-To-Many relation working. I have the following mappings:
In my Rails app I have a has_many_through relation. I want to use the
Let's say I have a has_many relation between User and Messages. I'd like to
i have two models. Batch and Subject. The relation between them are Batch HAS_MANY
I have a table in sql having two fields 'JOB_NUMBER' 'SRno', the relation between

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.