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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:32:25+00:00 2026-06-16T02:32:25+00:00

I’ve run through the Cakephp documentation on linking models together (creating associations), and I

  • 0

I’ve run through the Cakephp documentation on linking models together (creating associations), and I can get a single select dropdown in the scaffolded add and edit views by defining a $hasOne member one model and a corresponding $belongsTo in the other. Now, for a $hasMany relationship, I’m trying to get some kind of form input (either a multi-select dropdown, or checkboxes … preferably checkboxes) in my scaffolded add and edit views that lets the user choose the associated advertisements for a given rental. But with the below code I get no mention of Advertisements in the Rental add and edit views :'( Am I missing something? Is this even possible? I’ve seen this done in RoR and Grails but can’t get it working with CakePHP. Thanks for any help!

Rental model (app/Model/Rental.php)

<?php
class Rental extends AppModel {
    var $name = 'Rental';             
    var $belongsTo = array(
        'Agent' => array(
            'className'    => 'User',
            'foreignKey'    => 'agent_id'
        ),
        'Bedroom',
        'Landlord' => array(
            'className'    => 'Landlord',
            'foreignKey'    => 'landlord_id'
        )
    );  
    var $hasMany = array(
        'Advertisement' => array(
            'className'     => 'Advertisement',
            'foreignKey'    => 'rental_id',
            //'conditions'    => array('Comment.status' => '1'),
            'order'    => 'Advertisement.created DESC',
            'limit'        => '5',
            'dependent'=> false
        )
    );

    public $validate = array(
        'title' => array(
            'rule' => 'notEmpty'
        ),
        'description' => array(
            'rule' => 'notEmpty'
        )
    );

    public function isOwnedBy($rental, $user) {
        return $this->field('id', array('id' => $rental, 'user_id' => $user)) === $rental;
    }
}

Rentals Controller (app/Controller/RentalsController.php)

<?php
class RentalsController extends AppController {
    public $scaffold;
}

Advertisement model (app/Model/Advertisement.php)

<?php
class Advertisement extends AppModel {
    var $name = 'Advertisement';                   
    var $belongsTo = array(
        'Rental' => array(
            'className'    => 'Rental',
            'foreignKey'    => 'rental_id'
        ),
        'Author' => array(
            'className'    => 'User',
            'foreignKey'    => 'author_id'
        )
    ); 
}

Advertisements Controller (app/Controller/AdvertiesementsController.php)

<?php
class AdvertisementsController extends AppController {
    public $scaffold;
}
  • 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-16T02:32:27+00:00Added an answer on June 16, 2026 at 2:32 am

    Cake’s scaffold views don’t show anything from the hasMany side of the relationship. They assume you want to pick it from the model that has the belongsTo.

    Frankly, doing it as a multi-select is a little odd for this relationship, IMHO. Multi-selects are normally used for hasAndBelongsToMany relationships. If you want to do it, you’ll need to do the work yourself, and not use Cake’s scaffolding.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

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.