New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CDbCriteria add new method createFindCommand #2659
Comments
I think it may be useful. |
described that in first post, read comments "//".
as you see, those issues are closed and never will be implemented in Yii1 because of their difficulty, this approach is easy and useful shortcut, what is wrong? I understand that CDbCriteria acts like "lets replace array with value object and pass it into AR find methods". Also this can help in REST api. |
Okay, didn't get the full meaning of it as they where comments. So what you are proposing is this, right? class CDbCriteria {
// ...
public function createFindCommand($tableName)
{
return $this->getDbConnection()->getCommandBuilder()->createFindCommand($tableName, $this);
}
public function getDbConnection()
{
return Yii::app()->getComponent($this->connectionId); //also add here CDbConnection class check
]
Nothing's wrong I just wanted to mention that they are related. I am just not sure whether this should be a method of AR or CDbCriteria as the AR object has a criteria and also has a CDbConnection it might better be placed there. An important thing to mention is that this method would not allow to do anything with relational query, so |
yes, but this is first sketch ofcourse, but is very simple and like 90% will be like this, yes.
no, this method is just for array data and simple select-commands that can be constructed "on the fly", nothing more, it should not belong to AR, because of CDbCriteria only serves as simple value-object for AR, so this method shoud not be there i think. But ofcourse other cases can be mentioned here and discussed.
right, little price because of CDbCriteria was first design only for AR. |
Or maybe we can add some new method to |
I just added an issue exactly like this: #2872. I proposed to add a createCommand() in CActiveFinder. I think it resolves this issue too and also uses the 'with' property of CDbCriteria. |
not sure if it solves this problem, but now i need to create CActiveFinder each time for that, but i want to avoid doing so, because this class is more |
A public method in CActiveFinder is needed anyway to be able to call it from outside. If you don't like the solution please propose a method in CActiveRecord that would wrap the example call I provided. |
i dont think that this method must be in AR. |
I'm sorry but your comments are not very constructive. Where should it be then? CDbCriteria always applies to a specific model when fetching data. It's database agnostic on it's own and to resolve joins it needs to be supplied with a db connection that holds a schema referenced in the joins. |
calm down, or i will be ignoring your messages because of personal attacks.
yes, it is so because of About your method propose, yes it can be also in |
So as CDbCriteria acts like a query-object pattern and smth. like in Query in Yii2, i suggest to add new method to CDbCriteria, because of sometimes you dont need to use AR or populate models, just need simple command. So overall method can looks like this:
Based on this also:
http://www.yiiframework.com/forum/index.php/topic/31900-create-a-cdbcommand-from-a-cdbcriteria/
The text was updated successfully, but these errors were encountered: