Yii Framework Forum: combine two table into one table - Yii Framework Forum

Jump to content

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

combine two table into one table Rate Topic: -----

#1 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 26 April 2010 - 01:50 AM

Hi, I confused what the suitable title for this questions.

I have two table ( Content and Content_Detail)
this table is use for multilanguage Content.

each I will grab the content I always use this command:
$model = Content::model()->with('Content_Detail')->findAll("Content_Detail.lang = :lang", array(":lang" => Yii::app()->language 
))

yes this way is correct, but I feel tired if each I need to grab the content I have to use this way. this way is too long and not efisien I think.

are there are any way to use like this script above that more simple?
Thanks and Kind Regards
------
DanDinDun
0

#2 User is offline   Vince. 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 432
  • Joined: 29-December 08
  • Location:Los Angeles,CA

Posted 26 April 2010 - 02:17 AM

Yes you can define a default scope or a scope and use those instead of applying it to each query.

See

http://www.yiiframew...ultScope-detail
http://www.yiiframew...d#scopes-detail
Vince Gabriel, Lead Developer.
Posted ImagePosted ImagePosted Image
0

#3 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 26 April 2010 - 09:08 AM

View PostVince., on 26 April 2010 - 02:17 AM, said:

Yes you can define a default scope or a scope and use those instead of applying it to each query.

See

http://www.yiiframew...ultScope-detail
http://www.yiiframew...d#scopes-detail



hi sir, thanks for reply.
can you give me an example to use with() in defaultScope sir ?
Thanks and Kind Regards
------
DanDinDun
0

#4 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 26 April 2010 - 11:26 AM

View PostVince., on 26 April 2010 - 02:17 AM, said:

Yes you can define a default scope or a scope and use those instead of applying it to each query.

See

http://www.yiiframew...ultScope-detail
http://www.yiiframew...d#scopes-detail


hi sir, I have try this
    public function defaultScope(){
        $criteria = new CDbCriteria();
        $criteria->with = array('ContentD');
        $criteria->condition = "ContentD.lang = :lang";
        $criteria->params = array(':lang' => Yii::app()->language );
        return $criteria;
    }


but there are error,

CDbException
Description
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ContentD.lang' in 'where clause'


and the "with" criteria is not work. becuase the query that resulted by the defaultScope() is
rror in querying SQL: SELECT COUNT(*) FROM `tsite_Content` `t` WHERE
(ContentD.lang = :lang) AND (parent_id = :parent_id)


oh my god!! very confused! please help me sir!
Thanks and Kind Regards
------
DanDinDun
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