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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:13:59+00:00 2026-05-27T00:13:59+00:00

I have a few models I’m trying to relate. One model is Item ,

  • 0

I have a few models I’m trying to relate.

One model is Item, one is Slide, and another is Asset.

Items have multiple slides beneath them. Assets are basically files that have been uploaded (images, mp3s, etc) and slides are where assets are displayed. Each slide has one asset, but a given asset might belong to multiple slides. A slide has an asset_id field defined.

I currently have the models defined as:

Slide

class Slide extends AppModel {
    var $name = 'Slide';

    var $order = array("Slide.order" => "asc");

    var $belongsTo = 'Item';

    var $hasOne = array(
        'Asset' => array(
          'className' => 'Asset',
            'foreignKey' => 'id',
            'dependent' => false
        )
    );

} // Slide class

Asset

class Asset extends AppModel {
    var $name = 'Asset';

    var $displayField = 'name';

    var $belongsTo= array(
        'Assetdir' => array(
            'className' => 'Assetdir',
            'foreignKey' => 'assetdir_id'
        ),
        'Slide' => array(
            'className' => 'Slide',
            'foreignKey' => 'id'
        )
    );  
} // Asset class

When I load a slide, I’m seeing its parent element, Item, come through in the returned data, but the associated asset is not. What am I doing wrong here?

  • 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-27T00:13:59+00:00Added an answer on May 27, 2026 at 12:13 am

    Actually I think this is a one-to-many relationship between Slide and Asset. From the Model associations page: belongsTo: the current model contains the foreign key. So, any model that has a foreign key to another one belongs to the other one.

    So the way I see it:

    Item:

    • hasMany Slide

    Slide:

    • belongsTo Item (with item_id)
    • belongsTo Asset (with asset_id)

    Asset:

    • hasMany Slide

    For retrieving the associated models you want, I’d suggest looking at the Containable behavior.

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

Sidebar

Related Questions

I have a few model classes with basic one-to-many relationships. For example, a book
I have a few models that contain static data, and I'm trying to cache
I have few similar models in Django: class Material(models.Model): title = models.CharField(max_length=255) class Meta:
I have a few models that need to have custom find conditions placed on
I have a few models: 'Article, Video, BlogPost, News, Commodity'. Each are in their
I have quite a few libraries and models that get loaded into a controller,
i have an entity-model file (edmx) file which contains few tables and few stored
Hi i am using django 1.2 .I my case i have few models which
If I have a models.py like class WidgetType(models.Model): name = models.CharField(max_length=200) class Widget(models.Model): typeid
I'm having a few integration issues. I have 2 models which need to be

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.