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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:23:08+00:00 2026-05-17T21:23:08+00:00

My Problem: Linked to my Employees table I’ve got an Address table containing a

  • 0

My Problem: Linked to my Employees table I’ve got an Address table containing a virtual field called full_name (I guess you can imagine by yourself what it does). I added the Containable Behaviour and this function

function beforeFind() {
    $this->contain('Address.full_name');
}

to my Employees model, so that I don’t have to call $this->contain(..) in every single controller action (I need the full_name field in pretty every action). BUT id doesn’t work then if the controller action does just a $this->Employee->find('all') (or read(..). Contrary, it works if

  • The controller action uses $this->paginate(); instead
  • $this->Employee->contain('Address.full_name'); gets called before the $this->Employee->find('all'); call. I can’t imagine the cause for this because after this explicit contain(..) call, contain(..) gets called again by the Model callback function beforeFind(), as a debug proofed which I inserted into the cake/libs/models/behaviours/containable.php:contain() function *cough*.
  • 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-17T21:23:09+00:00Added an answer on May 17, 2026 at 9:23 pm

    As far as I recall, a contain() statement only works once, for the query operation immediately following it. Subsequent queries will require their own contain() statement e.g.

    $this->Employee->contain('Address.full_name');
    $this->Employee->find('all'); //first find
    // returns all of Employee + Address.full_name
    
    $this->Employee->find('all'); //second find
    // returns all of Employee + all of Address + all of any other associated tables.
    

    I don’t recommend using contain() in beforeFind() as it is intended to modify specific returns. It soon becomes second nature to use it before each query where you will then have fine control of the data returned.

    If you have a widespread requirement for a limited return, you can set that up in the associations on the model.

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

Sidebar

Related Questions

Problem: I have an address field from an Access database which has been converted
I’m having a problem with a linked Informix table in MS SQL Server 2008r2.
I got some problem with the linked list I've written. I dunno if it's
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
I seem to have problem getting linked servers working to query between database/servers running
I am having a problem with a linked image. <TR class=a> <TD><A href=http://CA_NB_1_1-pr.jpg rel=lightbox><IMG
I'm trying to illustrate a doubly linked list problem. this is from an old
Hey, I have been having a problem with my linked servers. I am using
I have a little problem. At my application Im always building two linked combobox
I am having some trouble running this linked list implementation (containing words as data).

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.