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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:11:25+00:00 2026-06-09T05:11:25+00:00

i have three tables an i would insert one array to the database. Its

  • 0

i have three tables an i would insert one array to the database. Its one tv show, with many seasons. And the Seasons have many Episodes. Here are my tables:

shows

id
title
created
modified

seasons

id
shows_id
created
modified

episodes

id
seasons_id
title
created
modified

The Model files:

Show.php

<?php
class Show extends AppModel {
    public $name = 'Show';
    public $hasMany = 'Season';
}

Season.php

<?php
class Season extends AppModel {
    public $name        = 'Season';
    public $belongsTo   = 'Show';
    public $hasMany     = 'Episode';
}

Episode.php

<?php
class Episode extends AppModel {
    public $name = 'Episode';
    public $belongsTo = 'Season';
}

I had tried it with this Array:

$this->Show->create();

$sql_show = array(
    'Show' => array(
        'id'        => 2,
        'title'     => 'Super Mega Show',
    ),
    'Season' => array(
        array(
            'id'        => 1,
            'shows_id'  => 2,
            'Episode'   => array(
                array(
                    'id'    => 1,
                    'title' => 'Episode Title 1'
                ),
                array(
                    'id'    => 2,
                    'title' => 'Episode Title 2 '
                ),
                array(
                    'id'    => 3,
                    'title' => 'Episode Title 3'
                ),
            )
        ),
    )
);


$this->Show->saveAll($sql_show);

How can i insert this array?

greetings

  • 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-09T05:11:26+00:00Added an answer on June 9, 2026 at 5:11 am

    You can try the following code to save multiple associated data:

     $this->Show->save($sql_show, array('deep' => true));
    

    You can also try it using saveAssociated() method.

    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

I have three tables: Employee(EmployeeID,Fname,Lname...) ProjectHeader(ProjectID,LeadID,Status....) ProjectDetails(ProjectDetailsID,ProjectID....) Here's my current code: $get_projects = SELECT
I have three tables in a Mysql database - countries, cities and hotels. Their
I have three tables in a MySQL database used in a music library application:
I've got three tables I would like to query for a single dataset. Here
I have two database tables, one in MYSQL and one in MSSQL. Both have
I would like to insert an array into a MYSQL database, preferably using Yii's
I have two tables with a many-to-one relationship. (Oracle) **Table: PARENT** Field: A (PK)
I have very long multidimensional array that have many sub arrays. I would like
There are two tables, which have a relationship(one-to-many). There are Meals table which contains
I have three tables. I have to retrieve the data using Linq statement. My

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.