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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:03:25+00:00 2026-06-10T20:03:25+00:00

I have several models with relations and what I am trying to do is

  • 0

I have several models with relations and what I am trying to do is to search the fields with the aliases I provide in DetailView. It looks like this

<?php $this->widget('bootstrap.widgets.BootGridView',array(
    'id'=>'operations-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'operationType.name:raw:Operation',
        'creation_date:datetime',
        'modification_date:datetime',
        'ammount_usd:raw:Ammount',
        'currency.short',
        /*

        'client_id',
        'organization_id',
        */
        array(
            'class'=>'bootstrap.widgets.BootButtonColumn',
        ),
    ),
)); ?>

And what I want is to be able to search through rows using the aliases for columns like currency.short. What is a correct approach to do that? Tried to modify the search() method like this..but I think I’m missing something.

public function search()
{
    // Warning: Please modify the following code to remove attributes that
    // should not be searched.

    $criteria=new CDbCriteria;

    $criteria->compare('creation_date',$this->creation_date,true);
    $criteria->compare('modification_date',$this->modification_date,true);
    $criteria->compare('ammount',$this->ammount,true);
    $criteria->compare('ammount_usd',$this->ammount_usd,true);
    $criteria->compare('currency_id',$this->currency_id);
    $criteria->compare('operation_type',operationType::model()->name);
    $criteria->compare('client_id',$this->client_id);
    $criteria->compare('organization_id',$this->organization_id);
$criteria->compare('comment',$this->comment);
    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
    ));
}

Thanks.

  • 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-10T20:03:27+00:00Added an answer on June 10, 2026 at 8:03 pm

    You have to create a virtual field for that property. For example in your main model:

    private _currencyshort = null;
    public function setCurrencyshort($value) {
        $this->_currencyshort = $value;
    }
    public function getCurrencyshort() {
        if ($this->_currencyshort === null && $this->currency != null)
        {
            $this->_currencyshort = $this->currency->short
        }
        return $this->_currencyshort;
    }
    public function search() {
        $criteria=new CDbCriteria;
        $criteria->with = array('currency'); // add more elements to array if you want to search by more relations
        $criteria->compare('currency.short',$this->currencyshort);
        // You can also add this field to your sorting criteria
        // ... etc
    }
    

    Also you have to add currencyshort into your rules() method of main model to the line where it states 'on'=>'search', for example:

    array('currencyshort', 'safe', 'on'=>'search'),
    

    Then in columns instead of currency.short you can put currencyshort and it will work with filters, sorting and etc.

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

Sidebar

Related Questions

I have several models grouped in a module like this: #/app/models/blobs/small_text.rb class Blobs::SmallText <
I have several Mongoid models that I'm running mapreduce on, and I'd like to
I have several 'lookup' fields in my models where I don't want nulls, but
In some Rspec model specs, we have several tests like this: it { should
I have several models with a date attribute and for each model I'd like
I have a django project with 2 apps like this: ## tags app, models.py
Let's say you have several models that contain fields for address, postal code, province/country,
I have several models with translations. When I load $this->tour = $this->getRoute()->getObject(); por example,
I have several fields in some of my database tables that my CakePHP models
I have several models that need to call a method that takes a particular

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.