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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:53:30+00:00 2026-06-15T12:53:30+00:00

I am in the FilesController and I’m trying to get a file based on

  • 0

I am in the FilesController and I’m trying to get a file based on the condition that its order belongs to the current user.

FilesController

// Check the file exists and that it belongs to the user

$this->File->find('first', array(
    'conditions' => array(
        'File.id' => $id,
        'Order.Customer.id' => $this->Auth->user('id')
    ),
    'recursive' => 2
));

Cake SQL Error

Unknown column 'Order.Customer.id' in 'where clause'

I’m trying to get the SQL to left join orders onto files and then left join customers onto orders, but I can’t figure out how to join the customers table, although I’m sure I’ve done this before. I’ve tried everything I can think of with the conditions, and using contains.

Here’s my model relationships:

Customer Model

class Customer extends AppModel {

    public $hasMany = array('Order');

}

Order Model

class Order extends AppModel {

    public $belongsTo = array('Customer');

    public $hasMany = array('File');

}

File Model

class File extends AppModel {

    public $belongsTo = array('Order');

}
  • 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-15T12:53:31+00:00Added an answer on June 15, 2026 at 12:53 pm

    I realised there is no need to actually join the customers table in this instance, because the orders table already has the customer_id.

    $this->File->find('first', array(
        'conditions' => array(
            'File.id' => $id,
            'Order.customer_id' => $this->Auth->user('id')
        )
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the hang of MVC framework so bear with me.
I'm trying to get rails to push the contents of a directory to Haml
Ive been trying to get this to work for 3 days now. I cant
I want to upload and then process a file in a Ruby on Rails
I am trying to understand and practice the MVC-pattern to improve my development. So
I am trying to upload files using Spring CommonsMultipartResolver however the controller is not
I'm trying to save multiple models but have problem with the dropdownlist of the
If the file name contains accents, it works as expected in Opera, FF, Chrome
Hey guys trying to declare a variable in CakePHP in the Fields Controller. This
GETTING THIS ERROR WHEN UPLOADING A FILE : LoadError (no such file to load

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.