Yii update criteria


















The method will properly quote the column name and escape values in the range. Note that you should choose to either set the full query text, or to use the functions. For example, you cannot do :. The API links get you in a redirect loop and appearantly it can't be fixed.

API Documentation for Yii 1. Version 1. All Packages Properties Methods. It is usually created by calling CDbConnection::createCommand. The SQL statement to be executed may be set via Text. To execute a non-query SQL such as insert, delete, update , call execute. Call bindValue to bind a value to an SQL parameter. When binding a parameter, the SQL statement is automatically prepared. You may also call prepare to explicitly prepare an SQL statement.

Starting from version 1. CDbCommand join mixed Returns the join part in the query. CDbCommand asa Returns the named behavior object. CComponent attachBehavior Attaches a behavior to this component. CComponent attachBehaviors Attaches a list of behaviors to the component. CComponent attachEventHandler Attaches an event handler to an event. CDbCommand bindValue Binds a value to a parameter. CDbCommand bindValues Binds a list of values to the corresponding parameters.

CComponent canSetProperty Determines whether a property can be set. CDbCommand detachBehavior Detaches a behavior from the component. CComponent detachBehaviors Detaches all behaviors from the component. CComponent detachEventHandler Detaches an existing event handler. CComponent disableBehavior Disables an attached behavior. CComponent disableBehaviors Disables all behaviors attached to this component. CDbCommand enableBehavior Enables an attached behavior.

CComponent enableBehaviors Enables all behaviors attached to this component. CDbCommand getJoin Returns the join part in the query. CDbCommand hasEvent Determines whether an event is defined.

CComponent hasEventHandler Checks whether the named event has attached handlers. CComponent hasProperty Determines whether a property is defined. CDbCommand raiseEvent Raises an event. CDbCommand reset Cleans up the command and prepares for building a new query. CDbCommand setJoin Sets the join part in the query.

Bound with '. The SQL statement executed was: '. User Contributed Notes 2. Mixing text and function calls Note that you should choose to either set the full query text, or to use the functions.

Details of where The API links get you in a redirect loop and appearantly it can't be fixed. Leave a comment. Signup or Login in order to comment. Returns the underlying PDOStatement for this command It could be null if the statement is not prepared yet.

The default implementation raises the onAfterDelete event. You may override this method to do postprocessing after the record is deleted. Make sure you call the parent implementation so that the event is raised properly. This method is invoked after each record is instantiated by a find method. The default implementation raises the onAfterFind event. You may override this method to do postprocessing after each newly found record is instantiated.

Calls afterFind. This method is internally used. This method is invoked after saving a record successfully. The default implementation raises the onAfterSave event. You may override this method to do postprocessing after record saving. Applies the query scopes to the given criteria. This method merges dbCriteria with the given criteria parameter.

It then resets dbCriteria to be null. Returns the list of all attribute names of the model. This would return all column names of the table associated with this AR class. This method is invoked before an AR finder executes a count call. The count calls include count and countByAttributes The default implementation raises the onBeforeCount event.

If you override this method, make sure you call the parent implementation so that the event is raised properly. This method is invoked before deleting a record. The default implementation raises the onBeforeDelete event. You may override this method to do any preparation work for record deletion. This method is invoked before an AR finder executes a find call. The default implementation raises the onBeforeFind event.

For details on modifying query criteria see onBeforeFind event. Calls beforeFind. This method is invoked before saving a record after validation, if any. The default implementation raises the onBeforeSave event.

You may override this method to do any preparation work for record saving. Use isNewRecord to determine whether the saving is for inserting or updating record. Sets the parameters about query caching. This is a shortcut method to CDbConnection::cache. It changes the query caching parameter of the dbConnection instance. Finds the number of rows satisfying the specified query condition. Finds the number of rows that have the specified attribute values. Finds the number of rows using the given SQL statement.

Returns the default named scope that should be implicitly applied to all queries for this model. The default implementation simply returns an empty array.

You may override this method if the model needs to be queried with some default criteria e. Deletes rows with the specified condition. Deletes rows which match the specified attribute values. Deletes rows with the specified primary key. Compares current active record with another one. The comparison is made by comparing table name and the primary key values of the two active records.

Checks whether there is row satisfying the specified condition. Finds all active records satisfying the specified condition. Finds all active records that have the specified attribute values.

Finds all active records with the specified primary keys. Finds a single active record that has the specified attribute values. Finds a single active record with the specified primary key. Returns the named attribute value. If this is a new record and the attribute is not set before, the default column value will be returned. If this record is the result of a query and the attribute is not loaded, null will be returned.

Returns the text label for the specified attribute. This method overrides the parent implementation by supporting returning the label defined in relational object. In particular, if the attribute name is in the form of "post. Returns the related record s.

This method will return the related record s of the current record. Initializes this model. This method is invoked when an AR instance is newly created and has its scenario set. You may override this method to provide code that is needed to initialize the model e. Inserts a row into the table based on this active record attributes. If the table's primary key is auto-incremental and is null before insertion, it will be populated with the actual value after insertion.

Note, validation is not performed in this method. You may call validate to perform the validation. After the record is inserted to DB successfully, its isNewRecord property will be set false, and its scenario property will be set to be 'update'. Creates an active record instance. This method is called by populateRecord and populateRecords. You may override this method if the instance being created depends the attributes that are to be populated to the record.

For example, by creating a record based on the value of a column, you may implement the so-called single-table inheritance mapping. Returns the static model of the specified AR class. The model returned is a static instance of the AR class. It is provided for invoking class-level methods something similar to static class methods. Returns whether there is an element at the specified offset. This method is required by the interface ArrayAccess. This event is raised before an AR finder performs a count call.

If you want to access or modify the query criteria used for the count call, you can use getDbCriteria to customize it based on your needs. When modifying criteria in beforeCount you have to make sure you are using the right table alias which is different on normal count and relational call. You can use getTableAlias to get the alias used for the upcoming count call.

This event is raised before the record is deleted. By setting CModelEvent::isValid to be false, the normal delete process will be stopped. This event is raised before an AR finder performs a find call.

This can be either a call to CActiveRecords find methods or a find call when model is loaded in relational context via lazy or eager loading.

If you want to access or modify the query criteria used for the find call, you can use getDbCriteria to customize it based on your needs. When modifying criteria in beforeFind you have to make sure you are using the right table alias which is different on normal find and relational call. You can use getTableAlias to get the alias used for the upcoming find call.

Please note that modification of criteria is fully supported as of version 1. Earlier versions had some problems with relational context and applying changes correctly.

This event is raised before the record is saved. By setting CModelEvent::isValid to be false, the normal save process will be stopped. Creates an active record with the given attributes.

This method is internally used by the find methods. Creates a list of active records based on the input data. Returns the primary key of the associated database table. This method is meant to be overridden in case when the table is not defined with a primary key for some legency database.

If the table is already defined with a primary key, you do not need to override this method. The default implementation simply returns null, meaning using the primary key defined in the database.

Performs the actual DB query and populates the AR objects with the query result. This method is mainly internally used by other AR query methods. Refreshes the meta data for this AR class. By calling this method, this AR class will regenerate the meta data needed. This is useful if the table schema has been changed and you want to use the latest available table schema.

Make sure you have called CDbSchema::refresh before you call this method. Otherwise, old table schema data will still be used. This method should be overridden to declare related objects. Besides the above relation types, a special relation called STAT is also supported that can be used to perform statistical query or aggregational query.

It retrieves the aggregational information about the related objects, such as the number of comments for each post, the average rating for each product, etc. Note, for composite foreign keys, they can be either listed together, separated by commas or specified as an array in format of array 'key1','key2'. Additional options may be specified as name-value pairs in the rest array elements: 'select': string array, a list of columns to be selected. Column names should be disambiguated if they appear in an expression e.

Defaults to empty. Note, column references need to be disambiguated with prefix 'relationName. Note, this is only honored by lazy loading, not eager loading. It defaults to null, meaning the table alias is the same as the relation name.

This should be given as an array of name-value pairs. The condition specified here will be appended to the joining condition using the AND operator.

This option has been available since version 1. Saves the current record. The record is inserted as a row into the database table if its isNewRecord property is true usually the case when the record is created using the 'new' operator.

Otherwise, it will be used to update the corresponding row in the table usually the case if the record is obtained using one of those 'find' methods. Validation will be performed before saving the record. If the validation fails, the record will not be saved. Please Help I'm stuck. Improve this question. Skatox 3, 10 10 gold badges 40 40 silver badges 45 45 bronze badges.

PsychoX PsychoX 1, 4 4 gold badges 20 20 silver badges 42 42 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. HarryFink HarryFink 1, 1 1 gold badge 6 6 silver badges 6 6 bronze badges. Sign up or log in Sign up using Google.

Sign up using Facebook.



0コメント

  • 1000 / 1000