Yii Framework Forum: Problem Relations On Seach() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problem Relations On Seach() Rate Topic: -----

#1 User is offline   Lucas de Abreu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 03-January 13

Posted 04 January 2013 - 04:26 PM

Let's start with my tables:
create table IF NOT EXISTS module (
    id              int         not null primary key auto_increment,
    name         varchar(50) not null
);
create table IF NOT EXISTS status (
    id              int         not null primary key auto_increment,
    name         varchar(50) not null
);
create table IF NOT EXISTS module_status (
    id              int         not null primary key auto_increment,
    module_id       int         not null,
    status_id       int         not null,
    foreign key (module_id) references module (id),
    foreign key (status_id) references status (id)
);
create table IF NOT EXISTS company (
    id              int         not null primary key auto_increment,
    name            varchar(100) not null,
    cnpj            varchar(14) not null unique,
    phone           varchar(14),
    email           varchar(100),
    module_status_id int not null,
    foreign key (module_status_id) references module_status (id)
);


For each module have many status and one status can be on many company

What I want is, on company/admin.php make possible to see the status.name and filter them.

Soo what i tried to do:

public function search()
{
        $criteria=new CDbCriteria;
                
        $criteria->compare('t.id',$this->id);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('cnpj',$this->cnpj,true);
        $criteria->compare('phone',$this->phone,true);
        $criteria->compare('email',$this->email,true);
        
        //$criteria->compare('module_status_id',$this->module_status_id);
                
        $criteria->compare('moduleStatus.status.name', $this->moduleStatus->status->id, true);

        $criteria->with=array('moduleStatus');
                
        return new CActiveDataProvider($this, array(
                'criteria'=>$criteria,
        ));
}


The error came on this line:

        $criteria->compare('moduleStatus.status.name', $this->moduleStatus->status->id, true);




The error:

  Trying to get property of non-object


Anyone could help me?
0

#2 User is offline   Backslider 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 363
  • Joined: 23-July 09

Posted 04 January 2013 - 05:23 PM

I would do it like this, far more efficient:

http://www.mattiress...y-related-data/

Just substitute what I have used as "organisations" with your "status" table data.

Here is another way:

http://www.mattiress...code-execution/
We were all once expert at....... nothing.

yii-language-behavior

My Blog
0

#3 User is offline   Lucas de Abreu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 03-January 13

Posted 07 January 2013 - 02:46 PM

View PostBackslider, on 04 January 2013 - 05:23 PM, said:

I would do it like this, far more efficient:

http://www.mattiress...y-related-data/

Just substitute what I have used as "organisations" with your "status" table data.

Here is another way:

http://www.mattiress...code-execution/


Thx for the reply, I tried to do as you on your blog but something went wrong.
I'd like to know better why you did like that, and there is a way to do like I was trying?
0

#4 User is offline   Backslider 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 363
  • Joined: 23-July 09

Posted 08 January 2013 - 07:45 PM

View PostLucas de Abreu, on 07 January 2013 - 02:46 PM, said:

I'd like to know better why you did like that, and there is a way to do like I was trying?


It depends on the data, but the essential idea is to execute a single query, rather than a query for every single grid row being returned.
We were all once expert at....... nothing.

yii-language-behavior

My Blog
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users