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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:53:59+00:00 2026-06-04T01:53:59+00:00

So I have the following example tables: Table A: id name type hat_size created

  • 0

So I have the following example tables:

Table A:
id
name
type
hat_size
created

Table B:
id
name
type
favorite_food
created

Table C:
id
name
type
some_other_thing
created

Let’s say that I want to create a search with results from models A, B, and C using id, name, type, and created.

My goal would be to search all three tables, ordered by one of the fields (let’s use created as the ORDER_BY field), and limited to say, 20 results.

Normally I would simply do a Union of these, order by the field, and LIMIT the result.

Now, I know I can just create a raw query to do this… but that means that I have to rewrite the paginate methods, always sanitize, etc. Plus it’s clunky and not necessarily portable across multiple SQL databases. I’d prefer to do this a more MVC friendly way, using the models themselves, if possible.

What’s the best way I can approach this with CakePHP?

Thank you,
James

  • 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-04T01:54:00+00:00Added an answer on June 4, 2026 at 1:54 am

    One option is to create a VIEW which holds the UNION query. And then perform your Cake query on the view.

    I’m starting to avoid views recently, however, because of the difficulty in transferring them between servers (and the annoying DEFINER command that is usually included in exports).

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

Sidebar

Related Questions

Say for example, I have the following two tables: TableA { _id } TableB
Let's say I have the following 4 tables (for examples' sake): Owners, Trucks, Boxes,
AdventureWorks tables have Insert/Update/Delete anomalies. Isn't that considered bad design? Let's take for example
I have a table containing the following: name type id : INT date1 :
I have the following example in a SQL table Cust Group Sales A 1
Ok, I have an example table with the following information and query. First up
I have the following query in VBA: DoCmd.RunSQL INSERT INTO table (value) VALUES ('example')
I have the following example of what a user might type into a field
In my database table I have the following fields: Table Supplier: id name vehicles
I have the following table: select * from points +---------+-------------------+------+------+ | NAME | TITLE

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.