Yii Framework Forum: Findallbysql With Relation Models - Yii Framework Forum

Jump to content

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

Findallbysql With Relation Models Rate Topic: -----

#1 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,325
  • Joined: 21-February 11
  • Location:Greece

Posted 13 December 2013 - 03:58 AM

Hi

Recently I used findAllbySql but I have two questions

1)
MyModel::model()->findAllbySql("SELECT * FROM MyModel_table WHERE...");

Why have to use both MyModel and MyModel_table (in query) ?
Is not statement MyModel:: ... agile enough to include the part of query FROM MyModel_table ? What happens if (FROM MyModel_table) not included?
I thing this is surplus, is there specific reason to implemented findAllbySql and findbySql like that ?

2)According to above

MyModel::model()->with('relatedModel')->findAllbySql("SELECT * FROM MyModel_table LEFT JOIN relatedModel_table WHERE...")
needs JOIN relatedModel_table to works

I know with('...') used to load also the relation model, but I refer because
MyModel::model()->with('relatedModel')->findAll('t.attr>10 AND relatedModel.arr2<20'); works fine.

So, is there surplus too ?

Many thanks
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,598
  • Joined: 04-March 10
  • Location:UK

Posted 13 December 2013 - 04:16 AM

The findAllBySql() method needs to be able to handle arbitrarily complex SQL expressions. It wouldn't make sense for the framework to try to inject code just under specific circumstances.

If your queries are simple, they can be easily expressed using standard Active Record methods. If they're complicated, you probably won't want the framework to second guess you.
0

#3 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,325
  • Joined: 21-February 11
  • Location:Greece

Posted 13 December 2013 - 04:33 AM

View PostKeith, on 13 December 2013 - 04:16 AM, said:

The findAllBySql() method needs to be able to handle arbitrarily complex SQL expressions. It wouldn't make sense for the framework to try to inject code just under specific circumstances.

If your queries are simple, they can be easily expressed using standard Active Record methods. If they're complicated, you probably won't want the framework to second guess you.


Thank Keith

I wanted to be sure
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
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