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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:43:54+00:00 2026-06-14T07:43:54+00:00

My $condition in find() cannot make use of virtualfield. I have this virtualfield on

  • 0

My $condition in find() cannot make use of virtualfield.

I have this virtualfield on my Employee model:

        var $virtualFields = array(
            'AgentFullName' => "CONCAT(Employee.id, ' ', Employee.emp_ape_pat, ' ', Employee.emp_ape_mat, ' ', Employee.name)"
        );

I’m using this condition to look on two fields, one regular, one virtual (

        $idconditions = array(
            'OR' => array(
                'Employee.id LIKE' => $this->passedArgs['valsearch'],
                'Employee.AgentFullName LIKE' => $this->passedArgs['valsearch']
                ));

My find returns no record when looking for a valid text that can be found on the virtual field:

        $theid = $this->Horario->Employee->find('first', array(
            'fields' => array('Employee.emp_appserial', 'Employee.AgentFullName'),
            'conditions' => $idconditions,
                ));

However, the sql_dump seems correct:

When find() looks for an id number:

SELECT `Employee`.`emp_appserial`, (CONCAT(`Employee`.`id`, ' ', `Employee`.`emp_ape_pat`, ' ', `Employee`.`emp_ape_mat`, ' ', `Employee`.`name`)) AS `Employee__AgentFullName` FROM `devopm0_5`.`employees` AS `Employee` WHERE ((`Employee`.`id` LIKE 1005) OR ((CONCAT(`Employee`.`id`, ' ', `Employee`.`emp_ape_pat`, ' ', `Employee`.`emp_ape_mat`, ' ', `Employee`.`name`)) LIKE '1005')) LIMIT 1

And the find() using last name (returns no record)

SELECT `Employee`.`emp_appserial`, (CONCAT(`Employee`.`id`, ' ', `Employee`.`emp_ape_pat`, ' ', `Employee`.`emp_ape_mat`, ' ', `Employee`.`name`)) AS `Employee__AgentFullName` FROM `devopm0_5`.`employees` AS `Employee` WHERE ((`Employee`.`id` LIKE 'SMITH') OR ((CONCAT(`Employee`.`id`, ' ', `Employee`.`emp_ape_pat`, ' ', `Employee`.`emp_ape_mat`, ' ', `Employee`.`name`)) LIKE 'SMITH')) LIMIT 1

I wonder why the virtualfield cannot be subject to search.

Can you help?

Thank a lot !

  • 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-14T07:43:55+00:00Added an answer on June 14, 2026 at 7:43 am

    You cannot use VirtualFields as SQL Conditions.
    The virtual fields are added to the results after the find is performed, and this is why you cannot condition on them.
    The Cookbook says:

    These fields cannot be saved, but will be treated like other model fields for read operations. They will be indexed under the model’s key alongside other model fields.

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

Sidebar

Related Questions

I have this: var myError; function getNames(user,location){ myError=null; //Make an Ajax Call (this takes
Is there a way to create a condition like this? @products = Product.find(:all, :limit
Though I don't doubt this has been answered I cannot find a great match
I have got this problem: Find the first element in a list, for which
When I try to use dsolve to solve symbolically, it cannot find an explicit
I have looked and looked, but I cannot find a method that will allow
All, I cannot find any threads where this issue has been brought up before,
I've seen this topic somewhere on SO before, but cannot find it. What is
I'm trying to find prime numbers with a specific condition in Java. The challenge
I need to find the MPMovieplayerController is playing or not with condition. Check the

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.