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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:20:42+00:00 2026-05-19T23:20:42+00:00

I have two tables, users{name,id,age_range_id} and age_ranges{id,range_name} . There are also two models, controllers

  • 0

I have two tables, users{name,id,age_range_id} and age_ranges{id,range_name}.
There are also two models, controllers and the proper view files.

In the views I have the adduser.ctp file, which hold the proper form.
What I want is to have an input (select) that will hold the options from age_ranges.name field.
So, in the users model I’ve added var $hasMany = 'age_ranges';
What’s next?

I know that I can use the $this->set to store the options as an array in the controller and then use it in the view.
but I assume(wrongly?) that by relating the models there is an ‘automatic’ way to do it.
Which lead me to the question: how?

  • 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-19T23:20:42+00:00Added an answer on May 19, 2026 at 11:20 pm

    I won’t repeat what Thorpe and dogmatic have already written. They are both correct.

    However, although it’s difficult to be sure without seeing your model files, commonsense tells me that in the User model the relationship should be User:hasOne:AgeRange and in the AgeRange model it is AgeRange:hasMany:User, not the other way round as you have written.

    Also, you do not specify the table name (‘age_ranges’) in the relationship, but the Model name (‘AgeRange’).

    See these pages in the manual:

    http://book.cakephp.org/view/1001/Understanding-Models & http://book.cakephp.org/view/1039/Associations-Linking-Models-Together

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

Sidebar

Related Questions

I have two tables users - id - name - email users_groups - user_id
I have two tables Users (name, email, password, instance_id, etc...) example: james bond, james@abc.com,
Let's say you have two tables, Users and UserRoles. Here's how the two tables
I have a simple database with two tables. Users and Configurations. A user has
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
Let's say I have two or more tables filled with users and I want
I have two tables, like these: Table People: VARCHAR Name INTEGER Age Table Message
I have two html files information.html and employee.html. Information.html contains two tables having IDs
I have a table, users, in an Oracle 9.2.0.6 database. Two of the fields
I have two tables that are joined together. A has many B Normally you

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.