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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:14:19+00:00 2026-06-09T20:14:19+00:00

Basically, I want to build the relation between the tables ‘cities’ and ‘images’. They

  • 0

Basically, I want to build the relation between the tables ‘cities’ and ‘images’. They both have an ID column which is constrained by a third table called cities_images. Here’s the structure of the table in the middle:

CREATE TABLE IF NOT EXISTS `cities_images` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cityId` int(11) NOT NULL,
  `imageId` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `imageId` (`imageId`),
  KEY `cities_images_ibfk_2` (`cityId`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

ALTER TABLE `cities_images`
  ADD CONSTRAINT `cities_images_ibfk_2` FOREIGN KEY (`cityId`) REFERENCES `cities` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `cities_images_ibfk_1` FOREIGN KEY (`imageId`) REFERENCES `images` (`id`) ON DELETE CASCADE ON UPDATE CASCADE

I have two models that work with the cities and images tables.

Relation inside Cities.php:

'citiesImages' => array(self::MANY_MANY, 'CitiesImages', 'cities_images(id,cityId)'),

Relation inside Images.php:

'citiesImages' => array(self::MANY_MANY, 'CitiesImages', 'cities_images(id,imageId)'),

I am trying a test action inside CitiesController with the following content:

$cities = Cities::model()->findByPk(2);
var_dump($cities->images);exit;

But this results in an error:

Property “Cities.images” is not defined.

Note that there is a city with ID=2 and there is a row in cities_images with cityId=2 and imageId=1. There is also a row in the images table with ID=1, so I don’t see why I can’t access the images associated with the given City.

  • 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-09T20:14:21+00:00Added an answer on June 9, 2026 at 8:14 pm

    You are just referencing the wrong name. Should be:

    $cities = Cities::model()->findByPk(2);
    var_dump($cities->citiesImages);exit;
    

    Because that is how it is setup in the Cities.php model.

    UPDATE:

    Right, you need to simply change the models to point to the right model:

    Cities.php:

    'citiesImages' => array(self::MANY_MANY, 'Images', 'cities_images(imageId,cityId)'),
    

    Images.php:

    'citiesImages' => array(self::MANY_MANY, 'Cities', 'cities_images(cityId,imageId)'),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple web synchronization PHP I want to build which basically
I want to build a data structure which is basically a matrix of strings
I want to build a simple time ticker. Basically I will have a global
I want to build a web application which basically is a restful web-service serving
Basically I want to build a website based on some original content, the content
I want to build a bot that basically does the following: Listens to the
I'm working on a CMS basically because I want to learn how to build
I basically want to do: git checkout branchA git checkout -b branchB <commit_id> which
I want to build an app that is basically a subscription service for text
I am having problems creating a table in python. Basically I want to build

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.