クエリクラス
Class Query
基本のQueryクラスを拡張して、関連付けの読み込み、自動フィールド選択、自動型キャストに関連する新しいメソッドを提供し、必要に応じて結果をハイドレートする特定のイテレータに結果をラップします。
Extends the base Query class to provide new methods related to association loading, automatic fields selection, automatic type casting and to wrap results into a specific iterator that will be responsible for hydrating results if required.
定数の要約
Constants summary
プロパティの要約
Properties summary
-
$_autoFields protected
bool|null
元のクエリに最上位のテーブルのフィールドを含めるかどうかを追跡します。
Tracks whether or not the original query should include fields from the top level table.
-
$_beforeFindFired protected
bool
このクエリに対してbeforeFindイベントがすでにトリガーされている場合はtrue
True if the beforeFind event has already been triggered for this query
-
$_cache protected
\Cake\Datasource\QueryCacher|null
このクエリでキャッシュが有効になっている場合のクエリキャッシュインスタンス。
A query cacher instance if this query has caching enabled.
-
$_connection protected
\Cake\Database\Connection
このクエリの実行に使用される接続インスタンス。
Connection instance to be used to execute this query.
-
$_counter protected
callable|null
limit
を使用しない場合にこのクエリが一致するレコードの合計量を計算するために使用できる呼び出し可能な関数A callable function that can be used to calculate the total amount of records this query will match when not using
limit
-
$_deleteParts protected
string[]
DELETEステートメントを生成するために全探索するクエリ句のリスト
The list of query clauses to traverse for generating a DELETE statement
-
$_dirty protected
bool
このクエリの内部状態が変更されたかどうかを示します。これは、変換されたクエリや実行されたステートメントへの参照など、内部にキャッシュされたオブジェクトを破棄するために使用されます。
Indicates whether internal state of this query was changed, this is used to discard internal cached objects such as the transformed query or the reference to the executed statement.
-
$_eagerLoaded protected
bool
クエリがスタンドアロンであるか、熱心なロード操作の結果であるか。
Whether the query is standalone or the product of an eager load operation.
-
$_eagerLoader protected
\Cake\ORM\EagerLoader|null
関連付けの包含を格納し、このクエリが実行されたときにそれらを積極的にロードするクラスのインスタンス
Instance of a class responsible for storing association containments and for eager loading them when this query is executed
-
$_formatters protected
callable[]
フェッチ時に結果を後処理するフォーマッタクラスまたはコールバックのリスト
List of formatter classes or callbacks that will post-process the results when fetched
-
$_functionsBuilder protected
\Cake\Database\FunctionsBuilder|null
任意のSQL関数を生成するために使用される関数ビルダーオブジェクトのインスタンス。
Instance of functions builder object used for generating arbitrary SQL functions.
-
$_hasFields protected
bool|null
ユーザーが実行前にフィールドを選択するかどうかにかかわらず、これは、フィールドを自動的に選択する必要があるかどうかを決定するために使用されます。
Whether the user select any fields before being executed, this is used to determined if any fields should be automatically be selected.
-
$_hydrate protected
bool
結果をエンティティオブジェクトにハイドレートするかどうか
Whether to hydrate results into entity objects
-
$_insertParts protected
string[]
INSERTステートメントを生成するために全探索するクエリ句のリスト
The list of query clauses to traverse for generating an INSERT statement
-
$_iterator protected
\Cake\Database\StatementInterface|null
このクエリの実行結果のステートメントオブジェクト。
Statement object resulting from executing this query.
-
$_mapReduce protected
array
クエリ結果に適用する必要のあるmap-reduceルーチンのリスト
List of map-reduce routines that should be applied over the query result
-
$_options protected
array
このクラスのメソッドで処理できなかった、applyOptionsを使用して渡されたカスタムオプションを保持します。
Holds any custom options passed using applyOptions that could not be processed by any method in this class.
-
$_parts protected
array
このクエリの作成に使用されるSQLパーツのリスト。
List of SQL parts that will be used to build this query.
-
$_repository public
\Cake\ORM\Table
このクエリがバインドされているテーブルオブジェクトのインスタンス。
Instance of a table object this query is bound to.
-
$_resultDecorators protected
callable[]
取得時に結果のステートメントから各行を変更するために呼び出されるコールバック関数のリスト。 コールバック関数はそれぞれ、最初の引数として行配列を受け取ります。
A list of callback functions to be called to alter each row from resulting statement upon retrieval. Each one of the callback function will receive the row array as first argument.
-
$_results protected
iterable|null
ResultSet。
A ResultSet.
-
$_resultsCount protected
int|null
クエリの COUNT(*)。
The COUNT(*) for the query.
-
$_selectParts protected
string[]
SELECTステートメントを生成するために全探索するクエリ句のリスト
The list of query clauses to traverse for generating a SELECT statement
-
$_selectTypeMap protected
\Cake\Database\TypeMap
select句のフィールドのタイプマップ
The Type map for fields in the select clause
-
$_type protected
string
このクエリのタイプ(選択、挿入、更新、削除)。
Type of this query (select, insert, update, delete).
-
$_typeMap protected
\Cake\Database\TypeMap
-
$_updateParts protected
string[]
UPDATEステートメントを生成するために全探索するクエリ句のリスト
The list of query clauses to traverse for generating an UPDATE statement
-
$_useBufferedResults protected
bool
バッファリングされた結果が有効かどうかを追跡するためのブール値。
Boolean for tracking whether or not buffered results are enabled.
-
$_valueBinder protected
\Cake\Database\ValueBinder|null
クエリプレースホルダーを生成し、それぞれに関連付けられた値を一時的に格納するオブジェクト。
The object responsible for generating query placeholders and temporarily store values associated to each of those.
-
$typeCastEnabled protected
bool
キャストを無効にする追跡フラグ
Tracking flag to disable casting
メソッドの要約
Method Summary
-
__call() public
このクラスからであるかのように、結果セットからメソッドを呼び出すことができます。
Enables calling methods from the result set as if they were from this class
-
__clone() public
オブジェクトクローンフック。
Object clone hook.
-
__construct() public
コンストラクタ
Constructor
-
__debugInfo() public
このオブジェクトの内部状態を説明するために使用できる配列を返します。
Returns an array that can be used to describe the internal state of this object.
-
__toString() public
このクエリの文字列表現を返します(完全なSQLステートメント)。
Returns string representation of this query (complete SQL statement).
-
_addAssociationsToTypeMap() protected
含まれている関連列タイプをクエリに再帰的に追加するために使用されます。
Used to recursively add contained association column types to the query.
-
_addDefaultFields() protected
選択するセットフィールドがあるかどうかを検査します。それ以外の場合は、デフォルトテーブルのすべてのフィールドを追加します。
Inspects if there are any set fields for selecting, otherwise adds all the fields for the default table.
-
_addDefaultSelectTypes() protected
select句のフィールドを変換するためのデフォルトのタイプを設定します
Sets the default types for converting the fields in the select clause
-
_conjugate() protected
QueryExpressionオブジェクトを作成して条件を構築するために使用されるヘルパー関数。
Helper function used to build conditions by composing QueryExpression objects.
-
_decorateResults() protected
MapReduceルーチンとフォーマッターで結果イテレーターを装飾します
Decorates the results iterator with MapReduce routines and formatters
-
_decorateStatement() protected
登録済みのコールバックを使用して、ドライバーからの元のステートメントをラップするために使用される補助関数。
Auxiliary function used to wrap the original statement from the driver with any registered callbacks.
-
_decoratorClass() protected
結果の装飾に使用されるクラスの名前を返します
Returns the name of the class to be used for decorating results
-
_dirty() protected
クエリをダーティとしてマークし、前の結果などのメモリ内キャッシュから前処理済みの情報を削除します
Marks a query as dirty, removing any preprocessed information from in memory caching such as previous results
-
_execute() protected
このクエリを実行し、結果を含むResultSetオブジェクトを返します。
Executes this query and returns a ResultSet object containing the results.
-
_expressionsVisitor() protected
traverseExpressions()で使用されるクエリパーツトラバーサルメソッド
Query parts traversal method used by traverseExpressions()
-
_makeJoin() protected
単一の結合句を記述する結合メソッドに渡すことができる配列を返します
Returns an array that can be passed to the join method describing a single join clause
-
_performCount() protected
クエリのCOUNT(*)を実行して返します。
Performs and returns the COUNT(*) for the query.
-
_transformQuery() protected
クエリオブジェクトを実行する前に、デフォルトをいくつか適用します。
Applies some defaults to the query object before it is executed.
-
addDefaultTypes() public
データベースの条件をキャストするときに、このオブジェクトにヒントを付けて正しいタイプを関連付けます。 これは、渡されたテーブルオブジェクトに関連付けられたスキーマからフィールドタイプを抽出することによって行われます。 これにより、条件を指定するときにユーザーが自分自身を繰り返すのを防ぎます。
Hints this object to associate the correct types when casting conditions for the database. This is done by extracting the field types from the schema associated to the passed table object. This prevents the user from repeating themselves when specifying conditions.
-
aliasField() public
select()メソッドに直接渡すことができる単一のエイリアスフィールドを表すkey => value配列を返します。
Returns a key => value array representing a single aliased field that can be passed directly to the select() method.
-
aliasFields() public
指定されたリストの各フィールドに対して
aliasField()
を実行し、単一の配列で結果を返します。Runs
aliasField()
for each field in the provided list and returns the result under a single array. -
all() public
このクエリの結果をフェッチします。
Fetch the results for this query.
-
andHaving() public
HAVING句のAND演算子を使用して、以前に定義された条件のセットを指定されたリストに接続します。 このメソッドは
andWhere()
メソッドとまったく同じように動作します。 各パラメーターの使用方法については、そのドキュメントを参照してください。Connects any previously defined set of conditions to the provided list using the AND operator in the HAVING clause. This method operates in exactly the same way as the method
andWhere()
does. Please refer to its documentation for an insight on how to using each parameter. -
andWhere() public
AND演算子を使用して、以前に定義された条件のセットを指定されたリストに接続します。 {@see \Cake\Database\Query::andWhere()}
Connects any previously defined set of conditions to the provided list using the AND operator. {@see \Cake\Database\Query::andWhere()}
-
append() public
クエリの結果に行を追加します。
Appends more rows to the result of the query.
-
applyOptions() public
配列を使用して、パーツを現在のクエリ句に追加または追加します。
Populates or adds parts to current query clauses using an array.
-
bind() public
クエリプレースホルダーを値とタイプに関連付けます。
Associates a query placeholder to a value and a type.
-
cache() public
このクエリの結果キャッシュを有効にします。
Enable result caching for this query.
-
chunk() public
結果を$size行の配列にグループ化します。
Groups the results in arrays of $size rows each.
-
clause() public
指定された句に格納されたデータを返します。 これは、クエリの内部部分を変更する場合に役立ちます。SQL方言では、クエリを実行する前にそれに応じてクエリを変換するために使用されます。 取得できる有効な句は、削除、更新、設定、挿入、値、選択、区別、差出人、結合、設定、場所、グループ、所有、順序、制限、オフセット、およびユニオンです。
Returns any data that was stored in the specified clause. This is useful for modifying any internal part of the query and it is used by the SQL dialects to transform the query accordingly before it is executed. The valid clauses that can be retrieved are: delete, update, set, insert, values, select, distinct, from, join, set, where, group, having, order, limit, offset and union.
-
cleanCopy() public
この現在のクエリのコピーを作成し、beforeFindをトリガーして、一部の状態をリセットします。
Creates a copy of this current query, triggers beforeFind and resets some state.
-
clearContain() public
現在のクエリから含まれている関連付けをクリアします。
Clears the contained associations from the current query.
-
combine() public
$v列インデックスの値を$k列で返し、$gでグループ化します。
Returns the values of the column $v index by column $k, and grouped by $g.
-
contain() public
このクエリとともに積極的に読み込まれるべき関連のリストを設定します。 渡された関連テーブルのリストは、事前にテーブルAPIを使用して関連付けとして設定されている必要があります。
Sets the list of associations that should be eagerly loaded along with this query. The list of associated tables passed must have been previously set as associations using the Table API.
-
count() public
クエリの結果の合計量を返します。
Returns the total amount of results for the query.
-
countBy() public
列の一意の値の数を返します
Returns the number of unique values for a column
-
counter() public
このクエリの
count
メソッドが呼び出されたときに実行される呼び出し可能関数を登録します。 関数の戻り値は、count
メソッドの戻り値として設定されます。Registers a callable function that will be executed when the
count
method in this query is called. The return value for the function will be set as the return value of thecount
method. -
decorateResults() public
結果セットからフェッチされる各結果に対して実行されるコールバックを登録します。コールバック関数は、フェッチされたすべての行についてデータベースからの生データを含む配列を最初のパラメーターとして受け取り、可能な変更を含む行を返す必要があります。
Registers a callback to be executed for each result that is fetched from the result set, the callback function will receive as first parameter an array with the raw data from the database for every row that is fetched and must return the row with any possible modifications.
-
delete() public
削除クエリを作成します。
Create a delete query.
-
disableAutoFields() public
フィールドの自動追加を無効にしました。
Disables automatically appending fields.
-
disableBufferedResults() public
バッファリングされた結果を無効にします。
Disables buffered results.
-
disableHydration() public
水和エンティティを無効にします。
Disable hydrating entities.
-
disableResultsCasting() public
フィールドの対応するPHPデータ型への自動キャストを無効にします
Disables the automatic casting of fields to their corresponding PHP data type
-
distinct() public
DISTINCT
句をクエリに追加して、結果セットから重複を削除します。Adds a
DISTINCT
clause to the query to remove duplicates from the result set. -
each() public
各クエリ結果を呼び出し可能オブジェクトに渡します
Passes each of the query results to the callable
-
eagerLoaded() public
クエリインスタンスを熱心に読み込まれるクエリに設定します。 引数が渡されない場合、現在構成されているクエリの
_eagerLoaded
値が返されます。Sets the query instance to be an eager loaded query. If no argument is passed, the current configured query
_eagerLoaded
value is returned. -
enableAutoFields() public
ORMがフィールドを自動的に追加するかどうかを設定します。
Sets whether or not the ORM should automatically append fields.
-
enableBufferedResults() public
バッファリングされた結果を有効/無効にします。
Enables/Disables buffered results.
-
enableHydration() public
水和エンティティを切り替えます。
Toggle hydrating entities.
-
enableResultsCasting() public
フィールドを対応するタイプに自動キャストできるようにします
Enables the automatic casting of fields to their corresponding type
-
epilog() public
生成されたクエリに追加される文字列または式
A string or expression that will be appended to the generated query
-
every() public
すべての結果が呼び出し可能テストに合格した場合、trueを返します
Returns true if all the results pass the callable test
-
execute() public
このクエリのSQL表現をコンパイルし、構成された接続オブジェクトを使用して実行します。 結果のステートメントオブジェクトを返します。
Compiles the SQL representation of this query and executes it using the configured connection object. Returns the resulting statement object.
-
extract() public
各行から単一の列を抽出します
Extracts a single column from each row
-
filter() public
呼び出し可能テストに合格することで結果を保持します
Keeps the results using passing the callable test
-
find() public
既存のクエリオブジェクトに対してカスタム検索を適用します。
Apply custom finds to against an existing query object.
-
first() public
このクエリの実行から最初の結果を返します。クエリがまだ実行されていない場合は、パフォーマンス上の理由からlimit句が1に設定されます。
Returns the first result out of executing this query, if the query has not been executed before, it will set the limit clause to 1 for performance reasons.
-
firstOrFail() public
実行中のクエリから最初の結果を取得するか、例外を発生させます。
Get the first result from the executing query or raise an exception.
-
formatResults() public
データベースから結果をフェッチしようとするときに実行される新しいフォーマッターコールバック関数を登録します。
Registers a new formatter callback function that is to be executed when trying to fetch the results from the database.
-
from() public
このクエリのFROM句で使用される単一または複数のテーブルを追加します。
Adds a single or multiple tables to be used in the FROM clause for this query.
-
func() public
任意のSQL関数の生成に使用できる関数ビルダーオブジェクトのインスタンスを返します。
Returns an instance of a functions builder object that can be used for generating arbitrary SQL functions.
-
getConnection() public
このクエリの実行と変換に使用される接続インスタンスを取得します。
Gets the connection instance to be used for executing and transforming this query.
-
getContain() public
-
getDefaultTypes() public
現在の型マップのデフォルトの型を取得します。
Gets default types of current type map.
-
getEagerLoader() public
現在構成されているインスタンスを返します。
Returns the currently configured instance.
-
getIterator() public
このクエリを実行し、結果イテレータを返します。 この関数はIteratorAggregateインターフェースを実装するために必要であり、execute()を手動で呼び出さなくてもクエリを反復できるため、クエリ自体ではなく結果セットのように見えます。
Executes this query and returns a results iterator. This function is required for implementing the IteratorAggregate interface and allows the query to be iterated without having to call execute() manually, thus making it look like a result set instead of the query itself.
-
getMapReducers() public
以前に登録されたマップ削減ルーチンのリストを返します。
Returns the list of previously registered map reduce routines.
-
getOptions() public
このクエリに適用され、このクラスの別のメソッドでまだ処理されていないカスタムオプションを含む配列を返します。
Returns an array with the custom options that were applied to this query and that were not already processed by another method in this class.
-
getRepository() public
このクエリで使用されるデフォルトのテーブルオブジェクト、つまり、from句に表示されるテーブルを返します。
Returns the default table object that will be used by this query, that is, the table that will appear in the from clause.
-
getResultFormatters() public
以前に登録されたフォーマットルーチンのリストを返します。
Returns the list of previously registered format routines.
-
getSelectTypeMap() public
select句の各フィールドの型が格納されているTypeMapクラスを取得します。
Gets the TypeMap class where the types for each of the fields in the select clause are stored.
-
getTypeMap() public
既存の型マップを返します。
Returns the existing type map.
-
getValueBinder() public
現在使用されているValueBinderインスタンスを返します。
Returns the currently used ValueBinder instance.
-
group() public
このクエリのGROUP BY句で使用される単一または複数のフィールドを追加します。
Adds a single or multiple fields to be used in the GROUP BY clause for this query.
-
groupBy() public
インメモリは、列の値によってすべての結果をグループ化します。
In-memory group all results by the value of a column.
-
having() public
このクエリの
HAVING
句で使用される条件または条件セットを追加します。 このメソッドは、where()
メソッドとまったく同じように動作します。 各パラメーターの使用方法については、そのドキュメントを参照してください。Adds a condition or set of conditions to be used in the
HAVING
clause for this query. This method operates in exactly the same way as the methodwhere()
does. Please refer to its documentation for an insight on how to using each parameter. -
identifier() public
識別子を参照する式を作成します。 識別子を使用してフィールド名を参照し、SQLコンパイラが引用符を適用したり、識別子をエスケープしたりできるようにします。
Creates an expression that refers to an identifier. Identifiers are used to refer to field names and allow the SQL compiler to apply quotes or escape the identifier.
-
indexBy() public
列の値で索引付けされた結果を返します。
Returns the results indexed by the value of a column.
-
innerJoin() public
クエリに単一の
INNER JOIN
句を追加します。Adds a single
INNER JOIN
clause to the query. -
innerJoinWith() public
渡された関連付けテーブルを使用してINNER JOINを作成しますが、外部キーの一致と、最初に設定されたカスタム条件を保持します。
Creates an INNER JOIN with the passed association table while preserving the foreign key matching and the custom conditions that were originally set for it.
-
insert() public
挿入クエリを作成します。
Create an insert query.
-
into() public
挿入クエリのテーブル名を設定します。
Set the table name for insert queries.
-
isAutoFieldsEnabled() public
ORMがフィールドを自動的に追加するかどうかを取得します。
Gets whether or not the ORM should automatically append fields.
-
isBufferedResultsEnabled() public
バッファリングされた結果が有効か無効かを返します。
Returns whether buffered results are enabled/disabled.
-
isEagerLoaded() public
現在構成されているクエリの
_eagerLoaded
値を返しますReturns the current configured query
_eagerLoaded
value -
isEmpty() public
このクエリで結果が見つからなかった場合はtrueを返します。
Returns true if this query found no results.
-
isHydrationEnabled() public
現在のハイドレーションモードを返します。
Returns the current hydration mode.
-
join() public
JOIN句として使用する単一または複数のテーブルをこのクエリに追加します。
Adds a single or multiple tables to be used as JOIN clauses to this query.
-
jsonSerialize() public
クエリを実行し、結果セットをJSONに変換します。
Executes the query and converts the result set into JSON.
-
last() public
クエリ結果の最後の行を返します
Return the last row of the query result
-
leftJoin() public
クエリに単一の
LEFT JOIN
句を追加します。Adds a single
LEFT JOIN
clause to the query. -
leftJoinWith() public
渡された関連付けテーブルを使用してLEFT JOINを作成しますが、外部キーの一致と、最初に設定されたカスタム条件を保持します。
Creates a LEFT JOIN with the passed association table while preserving the foreign key matching and the custom conditions that were originally set for it.
-
limit() public
データベースから取得するレコードの数を設定し、整数または整数に評価される式オブジェクトを受け入れます。
Sets the number of records that should be retrieved from database, accepts an integer or an expression object that evaluates to an integer.
-
map() public
callableを使用して各結果を変更します
Modifies each of the results using the callable
-
mapReduce() public
新しいMapReduceルーチンを登録して、データベース結果の上で実行します。マッパーと呼び出し元の両方の呼び出し可能オブジェクトは、呼び出し可能なオブジェクトである必要があります。
Register a new MapReduce routine to be executed on top of the database results Both the mapper and caller callable should be invokable objects.
-
matching() public
このクエリにフィルター条件を追加して、関連付けられたテーブルの条件に基づいて、関連付けられたテーブルから別のテーブルとの関係を持つ行のみを取得します。
Adds filtering conditions to this query to only bring rows that have a relation to another from an associated table, based on conditions in the associated table.
-
max() public
すべての結果の1つの列の最大値を返します。
Returns the maximum value for a single column in all the results.
-
min() public
すべての結果の1つの列の最小値を返します。
Returns the minimum value for a single column in all the results.
-
modifier() public
SELECT
で使用する単一または複数のSELECT
修飾子を追加します。Adds a single or multiple
SELECT
modifiers to be used in theSELECT
. -
nest() public
$nをネストキーとして使用して、$kの同じ値を持つ列$pの値をネストしてツリー構造を作成します。
Creates a tree structure by nesting the values of column $p into that with the same value for $k using $n as the nesting key.
-
newExpr() public
新しいQueryExpressionオブジェクトを返します。 これは、流れるようなインターフェイスを使用して複雑なクエリを作成するときに便利な機能です。 必要に応じて、サブクラスでこの関数をオーバーライドして、より専門的なQueryExpressionクラスを使用することもできます。
Returns a new QueryExpression object. This is a handy function when building complex queries using a fluent interface. You can also override this function in subclasses to use a more specialized QueryExpression class if required.
-
notMatching() public
このクエリにフィルタリング条件を追加して、関連付けられたテーブルの条件に基づいて、関連付けられたテーブルから別のものと一致しない行のみを取得します。
Adds filtering conditions to this query to only bring rows that have no match to another from an associated table, based on conditions in the associated table.
-
offset() public
元の結果セットからスキップするレコードの数を設定します。これは通常、大きな結果のページ付けに使用されます。 整数または整数に評価される式オブジェクトを受け入れます。
Sets the number of records that should be skipped from the original result set This is commonly used for paginating large results. Accepts an integer or an expression object that evaluates to an integer.
-
order() public
このクエリのORDER句で使用される単一または複数のフィールドを追加します。
Adds a single or multiple fields to be used in the ORDER clause for this query.
-
orderAsc() public
ASC方向のORDER BY句を追加します。
Add an ORDER BY clause with an ASC direction.
-
orderDesc() public
DESC方向を指定したORDER BY句を追加します。
Add an ORDER BY clause with a DESC direction.
-
page() public
必要な結果のページを設定します。
Set the page of results you want.
-
reduce() public
callableを使用して、すべての結果を単一の値に折りたたみます。
Folds all the results into a single value using the callable.
-
reject() public
呼び出し可能テストに合格した結果を削除します
Removes the results passing the callable test
-
removeJoin() public
結合が定義されている場合は削除します。
Remove a join if it has been defined.
-
repository() public
このクエリで使用されるデフォルトのTableオブジェクトを設定し、
FROM
句を形成します。Set the default Table object that will be used by this query and form the
FROM
clause. -
rightJoin() public
クエリに単一の
RIGHT JOIN
句を追加します。Adds a single
RIGHT JOIN
clause to the query. -
rowCountAndClose() public
このクエリのSQLを実行し、変更されたレコードの行数を返す前にステートメントをすぐに閉じます。
Executes the SQL of this query and immediately closes the statement before returning the row count of records changed.
-
sample() public
インメモリは結果をシャッフルし、それらのサブセットを返します。
In-memory shuffle the results and return a subset of them.
-
select() public
このクエリが実行されるときに
SELECT
ステートメントによって返される新しいフィールドを追加します。 フィールドは、文字列の配列、式オブジェクトの配列、単一の式、または単一の文字列として渡すことができます。Adds new fields to be returned by a
SELECT
statement when this query is executed. Fields can be passed as an array of strings, array of expression objects, a single expression or a single string. -
selectAllExcept() public
除外されたフィールドを除いて、渡されたテーブルに関連付けられているすべてのフィールドがクエリの選択句に追加されます。 渡された除外フィールドにはエイリアスを設定しないでください。
All the fields associated with the passed table except the excluded fields will be added to the select clause of the query. Passed excluded fields should not be aliased.
-
set() public
更新する1つまたは複数のフィールドを設定します。
Set one or many fields to update.
-
setConnection() public
このクエリの実行と変換に使用される接続インスタンスを設定します。
Sets the connection instance to be used for executing and transforming this query.
-
setDefaultTypes() public
実装オブジェクトのフィールドのデフォルトの型マッピングを上書きします。
Overwrite the default type mappings for fields in the implementing object.
-
setEagerLoader() public
アソシエーションのロードと包含の格納に使用する熱心なローダークラスのインスタンスを設定します。
Sets the instance of the eager loader class to use for loading associations and storing containments.
-
setResult() public
クエリの結果セットを設定します。
Set the result set for a query.
-
setSelectTypeMap() public
Select句の各フィールドの型が格納されるTypeMapクラスを設定します。
Sets the TypeMap class where the types for each of the fields in the select clause are stored.
-
setTypeMap() public
$typeMapが配列の場合は新しいTypeMapを作成し、それ以外の場合は指定された配列と交換します。
Creates a new TypeMap if $typeMap is an array, otherwise exchanges it for the given one.
-
setValueBinder() public
現在の値バインダーを上書き
Overwrite the current value binder
-
shuffle() public
インメモリは結果が返される順序をランダム化します
In-memory randomize the order the results are returned
-
skip() public
クエリ結果の先頭から一部の行をスキップします。
Skips some rows from the start of the query result.
-
some() public
結果の少なくとも1つが呼び出し可能テストに合格した場合にtrueを返します
Returns true if at least one of the results pass the callable test
-
sortBy() public
コールバックでクエリを並べ替えます
Sorts the query with the callback
-
sql() public
このオブジェクトのSQL表現を返します。
Returns the SQL representation of this object.
-
stopWhen() public
callableがtrueを返すまで、各行を返します。
Returns each row until the callable returns true.
-
sumOf() public
単一の列のすべての値の合計を返します
Returns the sum of all values for a single column
-
take() public
クエリ結果のメモリ内の制限とオフセット。
In-memory limit and offset for the query results.
-
toArray() public
このクエリの結果を含むキーと値の配列を返します。
Returns a key-value array with the results of this query.
-
toList() public
このクエリの結果を数値でインデックス付けされた配列で返します。
Returns a numerically indexed array with the results of this query.
-
traverse() public
指定されたすべての部分を反復します。 トラバース関数は、クロージャー内の変数またはインスタンス変数を使用して結果を集約できます。 この関数は、クエリの作成に使用されるすべてのクエリパーツをトラバースする方法として一般的に使用されます。
Will iterate over every specified part. Traversing functions can aggregate results using variables in the closure or instance variables. This function is commonly used as a way for traversing all query parts that are going to be used for constructing a query.
-
traverseExpressions() public
この関数はtraverse()関数と同様に機能しますが、式ツリー全体の完全な深さ走査を行う点が異なります。 これにより、このクエリ内に格納されている各ExpressionInterfaceオブジェクトに提供されているコールバック関数が、クエリの任意の部分のネストの深さで実行されます。
This function works similar to the traverse() function, with the difference that it does a full depth traversal of the entire expression tree. This will execute the provided callback function for each ExpressionInterface object that is stored inside this query at any nesting depth in any part of the query.
-
traverseParts() public
提供された部分を反復します。
Will iterate over the provided parts.
-
triggerBeforeFind() public
クエリのリポジトリオブジェクトでbeforeFindイベントをトリガーします。
Trigger the beforeFind event on the query's repository object.
-
type() public
このクエリのタイプを返します(選択、挿入、更新、削除)
Returns the type of this query (select, insert, update, delete)
-
union() public
このクエリでUNION演算子と組み合わせて使用する完全なクエリを追加します。 これは、このクエリの結果セットと、渡されたクエリによって返される結果セットを組み合わせるために使用されます。 異なるクエリでこのメソッドを複数回呼び出すことにより、必要な数のクエリを追加できます。
Adds a complete query to be used in conjunction with an UNION operator with this query. This is used to combine the result set of this query with the one that will be returned by the passed query. You can add as many queries as you required by calling multiple times this method with different queries.
-
unionAll() public
このクエリでUNION ALL演算子と組み合わせて使用する完全なクエリを追加します。 これは、このクエリの結果セットと、渡されたクエリによって返される結果セットを組み合わせるために使用されます。 異なるクエリでこのメソッドを複数回呼び出すことにより、必要な数のクエリを追加できます。
Adds a complete query to be used in conjunction with the UNION ALL operator with this query. This is used to combine the result set of this query with the one that will be returned by the passed query. You can add as many queries as you required by calling multiple times this method with different queries.
-
update() public
更新クエリを作成します。
Create an update query.
-
values() public
挿入クエリの値を設定します。
Set the values for an insert query.
-
where() public
このクエリのWHERE句で使用される条件または条件セットを追加します。 条件は、比較演算子を含むキーとしてフィールドの配列として表現できます。配列の値は、フィールドをそのようなリテラルと比較するために使用されます。 最後に、条件は単一の文字列または文字列の配列として表すことができます。
Adds a condition or set of conditions to be used in the WHERE clause for this query. Conditions can be expressed as an array of fields as keys with comparison operators in it, the values for the array will be used for comparing the field to such literal. Finally, conditions can be expressed as a single string or an array of strings.
-
whereInList() public
このクエリのWHERE句で使用されるIN条件または条件セットを追加します。
Adds an IN condition or set of conditions to be used in the WHERE clause for this query.
-
whereNotInList() public
このクエリのWHERE句で使用されるNOT IN条件または条件セットを追加します。
Adds a NOT IN condition or set of conditions to be used in the WHERE clause for this query.
-
whereNotNull() public
クエリにNOT NULL条件を追加する簡易メソッド
Convenience method that adds a NOT NULL condition to the query
-
whereNull() public
クエリにIS NULL条件を追加する簡易メソッド
Convenience method that adds a IS NULL condition to the query
-
zip() public
クエリと$cの両方の最初の結果を配列で返し、次に2番目の結果を返します。
Returns the first result of both the query and $c in an array, then the second results and so on.
-
zipWith() public
クエリの最初の行と各項目を使用して$cを呼び出した結果のそれぞれを返し、次に2番目の行を返します。
Returns each of the results out of calling $c with the first rows of the query and each of the items, then the second rows and so on.
メソッドの詳細
Method Detail
__call() public ¶
__call(string $method, array $arguments)
このクラスからであるかのように、結果セットからメソッドを呼び出すことができます。
Enables calling methods from the result set as if they were from this class
Parameters
-
string
$method -
呼び出すメソッド
the method to call
-
array
$arguments -
呼び出すメソッドの引数のリスト
list of arguments for the method to call
Returns
mixed
Throws
BadMethodCallException
非選択クエリに対してメソッドが呼び出された場合
if the method is called for a non-select query
BadMethodCallException
結果セットにそのようなメソッドが存在しない場合
if no such method exists in result set
__clone() public ¶
__clone()
オブジェクトクローンフック。
Object clone hook.
クローンの内部イテレーターを破棄し、値バインダーとeagerloaderインスタンスのクローンを作成します。
Destroys the clones inner iterator and clones the value binder, and eagerloader instances.
__construct() public ¶
__construct(\Cake\Database\Connection $connection, \Cake\ORM\Table $table)
コンストラクタ
Constructor
Parameters
-
\Cake\Database\Connection
$connection -
接続オブジェクト
The connection object
-
\Cake\ORM\Table
$table -
このクエリが開始されているテーブル
The table this query is starting on
__debugInfo() public ¶
__debugInfo()
このオブジェクトの内部状態を説明するために使用できる配列を返します。
Returns an array that can be used to describe the internal state of this object.
Returns
array
__toString() public ¶
__toString()
このクエリの文字列表現を返します(完全なSQLステートメント)。
Returns string representation of this query (complete SQL statement).
Returns
string
_addAssociationsToTypeMap() protected ¶
_addAssociationsToTypeMap(\Cake\ORM\Table $table, \Cake\Database\TypeMap $typeMap, array $associations)
含まれている関連列タイプをクエリに再帰的に追加するために使用されます。
Used to recursively add contained association column types to the query.
Parameters
-
\Cake\ORM\Table
$table -
関連付けを取得するテーブルインスタンス。
The table instance to pluck associations from.
-
\Cake\Database\TypeMap
$typeMap -
列をチェックするタイプマップ。 このタイプマップはCake\ORM\Query::addDefaultTypes()を介して間接的に変更されます
The typemap to check for columns in. This typemap is indirectly mutated via Cake\ORM\Query::addDefaultTypes()
-
array
$associations -
歩くアソシエーションのネストされたツリー。
The nested tree of associations to walk.
_addDefaultFields() protected ¶
_addDefaultFields()
選択するセットフィールドがあるかどうかを検査します。それ以外の場合は、デフォルトテーブルのすべてのフィールドを追加します。
Inspects if there are any set fields for selecting, otherwise adds all the fields for the default table.
_addDefaultSelectTypes() protected ¶
_addDefaultSelectTypes()
select句のフィールドを変換するためのデフォルトのタイプを設定します
Sets the default types for converting the fields in the select clause
_conjugate() protected ¶
_conjugate(string $part, mixed $append, mixed $conjunction, array $types)
QueryExpressionオブジェクトを作成して条件を構築するために使用されるヘルパー関数。
Helper function used to build conditions by composing QueryExpression objects.
Parameters
-
string
$part -
新しいパーツを追加するクエリパーツの名前
Name of the query part to append the new part to
-
string|array|\Cake\Database\ExpressionInterface|\Closure|null
$append -
追加する式またはビルダー関数。 追加します。
Expression or builder function to append. to append.
-
string
$conjunction -
パーツの操作に使用する結合のタイプ
type of conjunction to be used to operate part
-
array
$types -
クエリに値をバインドするために使用されるタイプ名の連想配列
associative array of type names used to bind values to query
_decorateResults() protected ¶
_decorateResults(\Traversable $result)
MapReduceルーチンとフォーマッターで結果イテレーターを装飾します
Decorates the results iterator with MapReduce routines and formatters
Parameters
-
\Traversable
$result -
元の結果
Original results
Returns
\Cake\Datasource\ResultSetInterface
_decorateStatement() protected ¶
_decorateStatement(\Cake\Database\StatementInterface $statement)
登録済みのコールバックを使用して、ドライバーからの元のステートメントをラップするために使用される補助関数。
Auxiliary function used to wrap the original statement from the driver with any registered callbacks.
Parameters
-
\Cake\Database\StatementInterface
$statement -
装飾される
to be decorated
Returns
\Cake\Database\Statement\CallbackStatement|\Cake\Database\StatementInterface
_decoratorClass() protected ¶
_decoratorClass()
結果の装飾に使用されるクラスの名前を返します
Returns the name of the class to be used for decorating results
Returns
string
_dirty() protected ¶
_dirty()
クエリをダーティとしてマークし、前の結果などのメモリ内キャッシュから前処理済みの情報を削除します
Marks a query as dirty, removing any preprocessed information from in memory caching such as previous results
_execute() protected ¶
_execute()
このクエリを実行し、結果を含むResultSetオブジェクトを返します。
Executes this query and returns a ResultSet object containing the results.
これにより、深い関連付けを積極的にロードするために、正しいステートメントクラスもセットアップされます。
This will also setup the correct statement class in order to eager load deep associations.
Returns
\Cake\Datasource\ResultSetInterface
_expressionsVisitor() protected ¶
_expressionsVisitor(mixed $expression, \Closure $callback)
traverseExpressions()で使用されるクエリパーツトラバーサルメソッド
Query parts traversal method used by traverseExpressions()
Parameters
-
\Cake\Database\ExpressionInterface|\Cake\Database\ExpressionInterface[]
$expression -
クエリ式または式の配列。
Query expression or array of expressions.
-
\Closure
$callback -
このクエリ内で見つかった各ExpressionInterfaceに対して実行されるコールバック。
The callback to be executed for each ExpressionInterface found inside this query.
_makeJoin() protected ¶
_makeJoin(mixed $table, mixed $conditions, mixed $type)
単一の結合句を記述する結合メソッドに渡すことができる配列を返します
Returns an array that can be passed to the join method describing a single join clause
Parameters
-
string|string[]
$table -
結合するテーブル
The table to join with
-
string|array|\Cake\Database\ExpressionInterface
$conditions -
参加に使用する条件。
The conditions to use for joining.
-
string
$type -
使用する結合タイプ
the join type to use
Returns
array
_performCount() protected ¶
_performCount()
クエリのCOUNT(*)を実行して返します。
Performs and returns the COUNT(*) for the query.
Returns
int
_transformQuery() protected ¶
_transformQuery()
クエリオブジェクトを実行する前に、デフォルトをいくつか適用します。
Applies some defaults to the query object before it is executed.
具体的にはFROM句を追加し、何も指定されていない場合はデフォルトのテーブルフィールドを追加し、contain
を使用して定義された熱心な関連付けに必要な結合を適用
Specifically add the FROM clause, adds default table fields if none are specified and applies the joins required to eager load associations defined using contain
また、select句の列のデフォルトタイプを設定します
It also sets the default types for the columns in the select clause
See Also
addDefaultTypes() public ¶
addDefaultTypes(\Cake\ORM\Table $table)
データベースの条件をキャストするときに、このオブジェクトにヒントを付けて正しいタイプを関連付けます。 これは、渡されたテーブルオブジェクトに関連付けられたスキーマからフィールドタイプを抽出することによって行われます。 これにより、条件を指定するときにユーザーが自分自身を繰り返すのを防ぎます。
Hints this object to associate the correct types when casting conditions for the database. This is done by extracting the field types from the schema associated to the passed table object. This prevents the user from repeating themselves when specifying conditions.
このメソッドは、連鎖のために同じクエリオブジェクトを返します。
This method returns the same query object for chaining.
Parameters
-
\Cake\ORM\Table
$table -
タイプをプルするテーブル
The table to pull types from
Returns
$this
aliasField() public ¶
aliasField(string $field, ?string $alias)
select()メソッドに直接渡すことができる単一のエイリアスフィールドを表すkey => value配列を返します。
Returns a key => value array representing a single aliased field that can be passed directly to the select() method.
キーにはエイリアスが含まれ、値には実際のフィールド名が含まれます。
The key will contain the alias and the value the actual field name.
フィールドが既にエイリアスされている場合、フィールドは変更されません。 $aliasが渡されない場合、このクエリのデフォルトテーブルが使用されます。
If the field is already aliased, then it will not be changed. If no $alias is passed, the default table for this query will be used.
Parameters
-
string
$field -
エイリアスするフィールド
The field to alias
-
string|null
$alias optional -
フィールドのプレフィックスに使用されるエイリアス
the alias used to prefix the field
Returns
array
aliasFields() public ¶
aliasFields(array $fields, ?string $defaultAlias)
指定されたリストの各フィールドに対してaliasField()
を実行し、単一の配列で結果を返します。
Runs aliasField()
for each field in the provided list and returns the result under a single array.
Parameters
-
array
$fields -
エイリアスするフィールド
The fields to alias
-
string|null
$defaultAlias optional -
デフォルトのエイリアス
The default alias
Returns
string[]
all() public ¶
all()
このクエリの結果をフェッチします。
Fetch the results for this query.
setResult()を介して結果セットを返すか、このクエリを実行して、結果のストリーミングの準備ができているResultSetDecoratorオブジェクトを返します。
Will return either the results set through setResult(), or execute this query and return the ResultSetDecorator object ready for streaming of results.
ResultSetDecoratorは、Cake\Collection\Collectionにあるメソッドを実装する走査可能なオブジェクトです。
ResultSetDecorator is a traversable object that implements the methods found on Cake\Collection\Collection.
Returns
\Cake\Datasource\ResultSetInterface
Throws
RuntimeException
このメソッドが非選択クエリで呼び出された場合。
if this method is called on a non-select Query.
andHaving() public ¶
andHaving(mixed $conditions, mixed $types)
HAVING句のAND演算子を使用して、以前に定義された条件のセットを指定されたリストに接続します。
このメソッドはandWhere()
メソッドとまったく同じように動作します。
各パラメーターの使用方法については、そのドキュメントを参照してください。
Connects any previously defined set of conditions to the provided list using the AND operator in the HAVING clause.
This method operates in exactly the same way as the method andWhere()
does.
Please refer to its documentation for an insight on how to using each parameter.
フィールドはクエリビルダーによってサニタイズされないため、ユーザーが指定したデータでの使用には適していません。
Having fields are not suitable for use with user supplied data as they are not sanitized by the query builder.
Parameters
-
string|array|\Cake\Database\ExpressionInterface|\Closure
$conditions -
HAVINGのAND条件。
The AND conditions for HAVING.
-
array
$types optional -
クエリに値をバインドするために使用されるタイプ名の連想配列
associative array of type names used to bind values to query
Returns
$this
See Also
andWhere() public ¶
andWhere(mixed $conditions, array $types = [])
AND演算子を使用して、以前に定義された条件のセットを指定されたリストに接続します。 {@see \Cake\Database\Query::andWhere()}
Connects any previously defined set of conditions to the provided list using the AND operator. {@see \Cake\Database\Query::andWhere()}
Parameters
-
mixed
$conditions -
array
$types = []
append() public ¶
append(array|\Traversable $items)
クエリの結果に行を追加します。
Appends more rows to the result of the query.
Parameters
-
array|\Traversable
$items
applyOptions() public ¶
applyOptions(array $options)
配列を使用して、パーツを現在のクエリ句に追加または追加します。
Populates or adds parts to current query clauses using an array.
これは、すべてのクエリ句を一度に渡すのに便利です。 オプション配列は以下を受け入れます。
This is handy for passing all query clauses at once. The option array accepts:
-
fields:
selectメソッドにマップします
fields: Maps to the select method
-
conditions:
whereメソッドにマップします
conditions: Maps to the where method
-
limit:
制限メソッドにマップします
limit: Maps to the limit method
-
order:
注文方法にマップします
order: Maps to the order method
-
offset:
オフセット方法にマップします
offset: Maps to the offset method
-
group:
グループメソッドにマップします
group: Maps to the group method
-
having:
持つメソッドにマップします
having: Maps to the having method
-
contain:
熱心な読み込みのための包含オプションにマップします
contain: Maps to the contain options for eager loading
-
join:
結合方法にマップします
join: Maps to the join method
-
page:
ページメソッドにマップします
page: Maps to the page method
Example:
$query->applyOptions([
'fields' => ['id', 'name'],
'conditions' => [
'created >=' => '2013-01-01'
],
'limit' => 10
]);
以下と同等です:
Is equivalent to:
$query
->select(['id', 'name'])
->where(['created >=' => '2013-01-01'])
->limit(10)
Parameters
-
array
$options -
適用されるオプション
the options to be applied
Returns
$this
bind() public ¶
bind(mixed $param, mixed $value, mixed $type)
クエリプレースホルダーを値とタイプに関連付けます。
Associates a query placeholder to a value and a type.
$query->bind(':id', 1, 'integer');
Parameters
-
string|int
$param -
$valueの引用バージョンで置き換えられるプレースホルダー
placeholder to be replaced with quoted version of $value
-
mixed
$value -
バインドされる値
The value to be bound
-
string|int|null
$type optional -
データベースに送信するときにキャストに使用されるマップされたタイプ名
the mapped type name, used for casting when sending to database
Returns
$this
cache() public ¶
cache(mixed $key, mixed $config)
このクエリの結果キャッシュを有効にします。
Enable result caching for this query.
クエリでキャッシュが有効になっている場合、実行時に次の処理が行われます。
If a query has caching enabled, it will do the following when executed:
-
$keyのキャッシュを確認します。
結果がある場合、SQLは実行されません。
代わりに、キャッシュされた結果が返されます。
Check the cache for $key. If there are results no SQL will be executed. Instead the cached results will be returned.
-
キャッシュされたデータが古くなっている/欠落している場合、クエリの実行時に結果セットがキャッシュされます。
When the cached data is stale/missing the result set will be cached as the query is executed.
Usage
// Simple string key + config
$query->cache('my_key', 'db_results');
// Function to generate key.
$query->cache(function ($q) {
$key = serialize($q->clause('select'));
$key .= serialize($q->clause('where'));
return md5($key);
});
// Using a pre-built cache engine.
$query->cache('my_key', $engine);
// Disable caching
$query->cache(false);
Parameters
-
\Closure|string|false
$key -
キャッシュキーまたはキャッシュキーを生成する関数。 関数を使用する場合、このクエリインスタンスは引数として提供されます。
Either the cache key or a function to generate the cache key. When using a function, this query instance will be supplied as an argument.
-
string|\Cake\Cache\CacheEngine
$config optional -
使用するキャッシュ構成の名前、またはキャッシュ構成インスタンス。
Either the name of the cache config to use, or a cache config instance.
Returns
$this
Throws
RuntimeException
非選択クエリをキャッシュしようとしたとき。
When you attempt to cache a non-select query.
chunk() public ¶
chunk(int $size)
結果を$size行の配列にグループ化します。
Groups the results in arrays of $size rows each.
Parameters
-
int
$size
clause() public ¶
clause(string $name)
指定された句に格納されたデータを返します。 これは、クエリの内部部分を変更する場合に役立ちます。SQL方言では、クエリを実行する前にそれに応じてクエリを変換するために使用されます。 取得できる有効な句は、削除、更新、設定、挿入、値、選択、区別、差出人、結合、設定、場所、グループ、所有、順序、制限、オフセット、およびユニオンです。
Returns any data that was stored in the specified clause. This is useful for modifying any internal part of the query and it is used by the SQL dialects to transform the query accordingly before it is executed. The valid clauses that can be retrieved are: delete, update, set, insert, values, select, distinct, from, join, set, where, group, having, order, limit, offset and union.
これらの各パーツの戻り値は異なる場合があります。 一部の句はQueryExpressionを使用して内部的に状態を保存し、一部は配列を使用し、他の句はブール値または整数を使用します。 これは、各句の戻り値の型の要約です。
The return value for each of those parts may vary. Some clauses use QueryExpression to internally store their state, some use arrays and others may use booleans or integers. This is summary of the return types for each clause.
-
update:
string更新するテーブルの名前
update: string The name of the table to update
-
set:
QueryExpression
set: QueryExpression
-
insert:
配列は、テーブルと列を含む配列を返します。
insert: array, will return an array containing the table + columns.
-
values:
値式
values: ValuesExpression
-
select:
配列、フィールドが設定されていない場合は空の配列を返します
select: array, will return empty array when no fields are set
-
distinct:
ブール
distinct: boolean
-
from:
テーブルの配列
from: array of tables
-
join:
配列
join: array
-
set:
配列
set: array
-
where:
QueryExpression、設定されていない場合はnullを返します
where: QueryExpression, returns null when not set
-
group:
配列
group: array
-
having:
QueryExpression、設定されていない場合はnullを返します
having: QueryExpression, returns null when not set
-
order:
OrderByExpression、設定されていない場合はnullを返します
order: OrderByExpression, returns null when not set
-
limit:
整数またはQueryExpression、設定されていない場合はnull
limit: integer or QueryExpression, null when not set
-
offset:
整数またはQueryExpression、設定されていない場合はnull
offset: integer or QueryExpression, null when not set
-
union:
配列
union: array
Parameters
-
string
$name -
返される句の名前
name of the clause to be returned
Returns
mixed
Throws
InvalidArgumentException
名前付き句が存在しない場合。
When the named clause does not exist.
cleanCopy() public ¶
cleanCopy()
この現在のクエリのコピーを作成し、beforeFindをトリガーして、一部の状態をリセットします。
Creates a copy of this current query, triggers beforeFind and resets some state.
次の状態がクリアされます:
The following state will be cleared:
-
autoFields
autoFields
-
限界
limit
-
オフセット
offset
-
マップ/リデュース関数
map/reduce functions
-
結果フォーマッタ
result formatters
-
順序
order
-
封じ込め
containments
このメソッドは、サブクエリを操作するときに役立つクエリクローンを作成します。
This method creates query clones that are useful when working with subqueries.
Returns
static
clearContain() public ¶
clearContain()
現在のクエリから含まれている関連付けをクリアします。
Clears the contained associations from the current query.
Returns
$this
combine() public ¶
combine(mixed $k, mixed $v, mixed $g)
$v列インデックスの値を$k列で返し、$gでグループ化します。
Returns the values of the column $v index by column $k, and grouped by $g.
Parameters
-
mixed
$k -
mixed
$v -
mixed
$g
contain() public ¶
contain(mixed $associations, mixed $override)
このクエリとともに積極的に読み込まれるべき関連のリストを設定します。 渡された関連テーブルのリストは、事前にテーブルAPIを使用して関連付けとして設定されている必要があります。
Sets the list of associations that should be eagerly loaded along with this query. The list of associated tables passed must have been previously set as associations using the Table API.
Example:
// Bring articles' author information
$query->contain('Author');
// Also bring the category and tags associated to each article
$query->contain(['Category', 'Tag']);
アソシエーションは、ドット表記またはネストされた配列を使用して任意にネストできます。これにより、このオブジェクトは、必要な関連データを取得するために実行する必要がある結合または追加のクエリを計算できます。
Associations can be arbitrarily nested using dot notation or nested arrays, this allows this object to calculate joins or any additional queries that must be executed to bring the required associated data.
Example:
// Eager load the product info, and for each product load other 2 associations
$query->contain(['Product' => ['Manufacturer', 'Distributor']);
// Which is equivalent to calling
$query->contain(['Products.Manufactures', 'Products.Distributors']);
// For an author query, load his region, state and country
$query->contain('Regions.States.Countries');
含まれている関連付けごとに選択された条件とフィールドを制御できます。
It is possible to control the conditions and fields selected for each of the contained associations:
Example:
$query->contain(['Tags' => function ($q) {
return $q->where(['Tags.is_popular' => true]);
}]);
$query->contain(['Products.Manufactures' => function ($q) {
return $q->select(['name'])->where(['Manufactures.active' => true]);
}]);
各関連付けは、eagerが読み込まれたときに特別なオプションを定義する場合があります。関連付けごとに設定できるオプションは次のとおりです。
Each association might define special options when eager loaded, the allowed options that can be set per association are:
-
foreignKey
: 両方のテーブルに一致する別のフィールドを設定するために使用されます。falseに設定されている場合、結合条件は自動的に生成されません。 falseは結合可能なアソシエーションでのみ使用でき、hasManyまたはbelongsToManyアソシエーションでは使用できません。foreignKey
: Used to set a different field to match both tables, if set to false no join conditions will be generated automatically.false
can only be used on joinable associations and cannot be used with hasMany or belongsToMany associations. -
fields
: 関連付けからフェッチする必要があるフィールドを含む配列。fields
: An array with the fields that should be fetched from the association. -
finder
: 関連するレコードをロードするときに使用するファインダー。 文字列としてのファインダーの名前、またはファインダーに渡すオプションを定義する配列。finder
: The finder to use when loading associated records. Either the name of the finder as a string, or an array to define options to pass to the finder. -
queryBuilder
: オプション配列の代わりに呼び出し可能オブジェクトを渡すことと同等です。queryBuilder
: Equivalent to passing a callable instead of an options array.
Example:
// Set options for the hasMany articles that will be eagerly loaded for an author
$query->contain([
'Articles' => [
'fields' => ['title', 'author_id']
]
]);
ファインダーは、オプションを使用するように構成できます。
Finders can be configured to use options.
// Retrieve translations for the articles, but only those for the `en` and `es` locales
$query->contain([
'Articles' => [
'finder' => [
'translations' => [
'locales' => ['en', 'es']
]
]
]
]);
関連付けを含める場合、外部キー列を含めることが重要です。 そうしないと、例外がトリガーされます。
When containing associations, it is important to include foreign key columns. Failing to do so will trigger exceptions.
// Use a query builder to add conditions to the containment
$query->contain('Authors', function ($q) {
return $q->where(...); // add conditions
});
// Use special join conditions for multiple containments in the same method call
$query->contain([
'Authors' => [
'foreignKey' => false,
'queryBuilder' => function ($q) {
return $q->where(...); // Add full filtering conditions
}
],
'Tags' => function ($q) {
return $q->where(...); // add conditions
}
]);
最初の引数を空にして呼び出され、$override
がtrueに設定されている場合、前のリストは空になります。
If called with an empty first argument and $override
is set to true, the previous list will be emptied.
Parameters
-
array|string
$associations -
照会するテーブルエイリアスのリスト。
List of table aliases to be queried.
-
callable|bool
$override optional -
関連付けのクエリビルダー、または関連付けが配列の場合、渡されたリストで前のリストをオーバーライドするかどうかのブール値は、デフォルトで前のリストと新しいリストをマージします。
The query builder for the association, or if associations is an array, a bool on whether to override previous list with the one passed defaults to merging previous list with the new one.
Returns
$this
count() public ¶
count()
クエリの結果の合計量を返します。
Returns the total amount of results for the query.
Returns
int
countBy() public ¶
countBy(string|callable $field)
列の一意の値の数を返します
Returns the number of unique values for a column
Parameters
-
string|callable
$field
counter() public ¶
counter(?callable $counter)
このクエリのcount
メソッドが呼び出されたときに実行される呼び出し可能関数を登録します。
関数の戻り値は、count
メソッドの戻り値として設定されます。
Registers a callable function that will be executed when thecount
method in this query is called. The return value for the function will be set as the return value of thecount
method.
これは、カウントを返すクエリを最適化する必要がある場合に特に役立ちます。たとえば、不要な結合を削除したり、group byを削除したり、推定行数を返したりします。
This is particularly useful when you need to optimize a query for returning the count, for example removing unnecessary joins, removing group by or just return an estimated number of rows.
コールバックは、最初の引数として、このクエリ自体ではなく、このクエリのクローンを受け取ります。
The callback will receive as first argument a clone of this query and not this query itself.
最初のパラメーターがnull値の場合、代わりに組み込みカウンター関数が呼び出されます
If the first param is a null value, the built-in counter function will be called instead
Parameters
-
callable|null
$counter -
カウンター値
The counter value
Returns
$this
decorateResults() public ¶
decorateResults(?callable $callback, bool $overwrite)
結果セットからフェッチされる各結果に対して実行されるコールバックを登録します。コールバック関数は、フェッチされたすべての行についてデータベースからの生データを含む配列を最初のパラメーターとして受け取り、可能な変更を含む行を返す必要があります。
Registers a callback to be executed for each result that is fetched from the result set, the callback function will receive as first parameter an array with the raw data from the database for every row that is fetched and must return the row with any possible modifications.
コールバックは遅延して実行されます。データベースで3行しかフェッチされない場合、3回呼び出されますが、カーソルでフェッチする行がまだある可能性があります。
Callbacks will be executed lazily, if only 3 rows are fetched for database it will called 3 times, event though there might be more rows to be fetched in the cursor.
コールバックは登録された順序でスタックされます。スタックをリセットしたい場合は、2番目のパラメーターをtrueに設定してこの関数を呼び出します。
Callbacks are stacked in the order they are registered, if you wish to reset the stack the call this function with the second parameter set to true.
スタックからすべてのデコレーターを削除する場合は、最初のパラメーターをnullに設定し、2番目のパラメーターをtrueに設定します。
If you wish to remove all decorators from the stack, set the first parameter to null and the second to true.
Example
$query->decorateResults(function ($row) {
$row['order_total'] = $row['subtotal'] + ($row['subtotal'] * $row['tax']);
return $row;
});
Parameters
-
callable|null
$callback -
結果がフェッチされたときに呼び出すコールバック。
The callback to invoke when results are fetched.
-
bool
$overwrite optional -
これがすべての既存のデコレータを追加または置き換える必要があるかどうか。
Whether or not this should append or replace all existing decorators.
Returns
$this
delete() public ¶
delete(?string $table)
削除クエリを作成します。
Create a delete query.
これにより、クエリタイプが「削除」に変更されます。 where()メソッドと組み合わせて、削除クエリを作成できます。
This changes the query type to be 'delete'. Can be combined with the where() method to create delete queries.
Parameters
-
string|null
$table optional -
未使用のパラメータ。
Unused parameter.
Returns
$this
disableAutoFields() public ¶
disableAutoFields()
フィールドの自動追加を無効にしました。
Disables automatically appending fields.
Returns
$this
disableBufferedResults() public ¶
disableBufferedResults()
バッファリングされた結果を無効にします。
Disables buffered results.
バッファリングを無効にすると、フェッチした結果が今後の反復で記憶されないため、メモリ消費が少なくなります。
Disabling buffering will consume less memory as fetched results are not remembered for future iterations.
Returns
$this
disableHydration() public ¶
disableHydration()
水和エンティティを無効にします。
Disable hydrating entities.
ハイドレーションを無効にすると、クエリではエンティティではなく配列の結果が返されます。
Disabling hydration will cause array results to be returned for the query instead of entities.
Returns
$this
disableResultsCasting() public ¶
disableResultsCasting()
フィールドの対応するPHPデータ型への自動キャストを無効にします
Disables the automatic casting of fields to their corresponding PHP data type
Returns
$this
distinct() public ¶
distinct(mixed $on, mixed $overwrite)
DISTINCT
句をクエリに追加して、結果セットから重複を削除します。
Adds a DISTINCT
clause to the query to remove duplicates from the result set.
この句は、selectステートメントでのみ使用できます。
This clause can only be used for select statements.
特定のフィールドまたはフィールドセットを共有する行に基づいて重複をフィルタリングする場合は、フィルタリングするフィールドの配列を渡すことができます。 このオプションは、すべてのデータベースシステムで完全にサポートされているわけではないことに注意してください。
If you wish to filter duplicates based of those rows sharing a particular field or set of fields, you may pass an array of fields to filter on. Beware that this option might not be fully supported in all database systems.
Examples:
// Filters products with the same name and city
$query->select(['name', 'city'])->from('products')->distinct();
// Filters products in the same city
$query->distinct(['city']);
$query->distinct('city');
// Filter products with the same name
$query->distinct(['name'], true);
$query->distinct('name', true);
Parameters
-
array|\Cake\Database\ExpressionInterface|string|bool
$on optional -
フィルタリングする個別のクラスまたはフィールドのリストを有効/無効にします
Enable/disable distinct class or list of fields to be filtered on
-
bool
$overwrite optional -
渡されたリストでフィールドをリセットするかどうか
whether to reset fields with passed list or not
Returns
$this
each() public ¶
each(callable $c)
各クエリ結果を呼び出し可能オブジェクトに渡します
Passes each of the query results to the callable
Parameters
-
callable
$c
eagerLoaded() public ¶
eagerLoaded(bool $value)
クエリインスタンスを熱心に読み込まれるクエリに設定します。
引数が渡されない場合、現在構成されているクエリの_eagerLoaded
値が返されます。
Sets the query instance to be an eager loaded query.
If no argument is passed, the current configured query _eagerLoaded
value is returned.
Parameters
-
bool
$value -
熱心にロードするかどうか。
Whether or not to eager load.
Returns
$this
enableAutoFields() public ¶
enableAutoFields(bool $value)
ORMがフィールドを自動的に追加するかどうかを設定します。
Sets whether or not the ORM should automatically append fields.
デフォルトでは、select()を呼び出すと自動フィールドが無効になります。 この方法で自動フィールドを再度有効にできます。
By default calling select() will disable auto-fields. You can re-enable auto-fields with this method.
Parameters
-
bool
$value optional -
有効にするにはtrue、無効にするにはfalseを設定します。
Set true to enable, false to disable.
Returns
$this
enableBufferedResults() public ¶
enableBufferedResults(bool $enable)
バッファリングされた結果を有効/無効にします。
Enables/Disables buffered results.
有効にすると、このクエリによって返される結果がバッファされます。 これにより、結果セットを複数回反復したり、キャッシュと反復の両方を行うことができます。
When enabled the results returned by this Query will be buffered. This enables you to iterate a result set multiple times, or both cache and iterate it.
無効にすると、フェッチした結果が今後の反復で記憶されなくなるため、メモリ消費が少なくなります。
When disabled it will consume less memory as fetched results are not remembered for future iterations.
Parameters
-
bool
$enable optional -
バッファリングを有効にするかどうか
Whether or not to enable buffering
Returns
$this
enableHydration() public ¶
enableHydration(bool $enable)
水和エンティティを切り替えます。
Toggle hydrating entities.
falseに設定すると、クエリに対して配列の結果が返されます。
If set to false array results will be returned for the query.
Parameters
-
bool
$enable optional -
ブール値を使用してハイドレーションモードを設定します。
Use a boolean to set the hydration mode.
Returns
$this
enableResultsCasting() public ¶
enableResultsCasting()
フィールドを対応するタイプに自動キャストできるようにします
Enables the automatic casting of fields to their corresponding type
Returns
$this
epilog() public ¶
epilog(mixed $expression)
生成されたクエリに追加される文字列または式
A string or expression that will be appended to the generated query
Examples:
$query->select('id')->where(['author_id' => 1])->epilog('FOR UPDATE');
$query
->insert('articles', ['title'])
->values(['author_id' => 1])
->epilog('RETURNING id');
Epliogのコンテンツは生のSQLであり、ユーザー指定のデータでの使用には適していません。
Epliog content is raw SQL and not suitable for use with user supplied data.
Parameters
-
string|\Cake\Database\Expression\QueryExpression|null
$expression optional -
追加する式
The expression to be appended
Returns
$this
every() public ¶
every(callable $c)
すべての結果が呼び出し可能テストに合格した場合、trueを返します
Returns true if all the results pass the callable test
Parameters
-
callable
$c
execute() public ¶
execute()
このクエリのSQL表現をコンパイルし、構成された接続オブジェクトを使用して実行します。 結果のステートメントオブジェクトを返します。
Compiles the SQL representation of this query and executes it using the configured connection object. Returns the resulting statement object.
クエリを実行すると、内部でいくつかのステップが実行されます。最初のステップでは、接続でこのオブジェクトを特定の方言に合わせて変換します。これにより、実際に実行される別のクエリオブジェクトが生成される可能性があります。 その直後、リテラル値が接続に渡されるため、安全な方法でクエリにバインドされます。 最後に、結果のステートメントは、必要に応じて取得された各行に対してコールバックを実行するカスタムオブジェクトで装飾されます。
Executing a query internally executes several steps, the first one is letting the connection transform this object to fit its particular dialect, this might result in generating a different Query object that will be the one to actually be executed. Immediately after, literal values are passed to the connection so they are bound to the query in a safe way. Finally, the resulting statement is decorated with custom objects to execute callbacks for each row retrieved if necessary.
結果のステートメントはトラバース可能であるため、配列の場合と同様に、任意のループで使用できます。
Resulting statement is traversable, so it can be used in any loop as you would with an array.
このメソッドをクエリサブクラスでオーバーライドして、クエリ実行に関する動作を装飾できます。
This method can be overridden in query subclasses to decorate behavior around query execution.
Returns
\Cake\Database\StatementInterface
extract() public ¶
extract(mixed $field)
各行から単一の列を抽出します
Extracts a single column from each row
Parameters
-
mixed
$field
filter() public ¶
filter(callable $c = null)
呼び出し可能テストに合格することで結果を保持します
Keeps the results using passing the callable test
Parameters
-
callable
$c = null
find() public ¶
find(string $finder, array $options)
既存のクエリオブジェクトに対してカスタム検索を適用します。
Apply custom finds to against an existing query object.
カスタム検索メソッドを組み合わせて相互に適用できます。
Allows custom find methods to be combined and applied to each other.
$repository->find('all')->find('recent');
上記は、単一のクエリに複数のファインダーメソッドをスタックする例です。
The above is an example of stacking multiple finder methods onto a single query.
Parameters
-
string
$finder -
使用するfinderメソッド。
The finder method to use.
-
array
$options optional -
ファインダーのオプション。
The options for the finder.
Returns
static
変更されたクエリを返します。
Returns a modified query.
first() public ¶
first()
このクエリの実行から最初の結果を返します。クエリがまだ実行されていない場合は、パフォーマンス上の理由からlimit句が1に設定されます。
Returns the first result out of executing this query, if the query has not been executed before, it will set the limit clause to 1 for performance reasons.
Example:
$singleUser = $query->select(['id', 'username'])->first();
Returns
\Cake\Datasource\EntityInterface|array|null
ResultSetからの最初の結果。
The first result from the ResultSet.
firstOrFail() public ¶
firstOrFail()
実行中のクエリから最初の結果を取得するか、例外を発生させます。
Get the first result from the executing query or raise an exception.
Returns
\Cake\Datasource\EntityInterface|array
ResultSetからの最初の結果。
The first result from the ResultSet.
Throws
Cake\Datasource\Exception\RecordNotFoundException
最初のレコードがない場合。
When there is no first record.
formatResults() public ¶
formatResults(?callable $formatter, mixed $mode)
データベースから結果をフェッチしようとするときに実行される新しいフォーマッターコールバック関数を登録します。
Registers a new formatter callback function that is to be executed when trying to fetch the results from the database.
コールバックをフォーマットすると、最初のパラメーター、つまり\Cake\Collection\CollectionInterface
を実装するオブジェクトが取得されます。
Formatting callbacks will get a first parameter, an object implementing \Cake\Collection\CollectionInterface
, that can be traversed and modified at will.
イテレータオブジェクトを返すにはコールバックが必要です。イテレータオブジェクトは、このクエリの結果の戻り値として使用されます。
フォーマッタ関数は、このクエリのすべてのMapReduce
ルーチンが実行された後に適用されます。
Callbacks are required to return an iterator object, which will be used as the return value for this query's result.
Formatter functions are applied after all the MapReduce
routines for this query have been executed.
2番目の引数がtrueに設定されている場合、以前のフォーマッターが消去され、渡された最初の引数に置き換えられます。
If the second argument is set to true, it will erase previous formatters and replace them with the passed first argument.
Example:
// Return all results from the table indexed by id
$query->select(['id', 'name'])->formatResults(function ($results) {
return $results->indexBy('id');
});
// Add a new column to the ResultSet
$query->select(['name', 'birth_date'])->formatResults(function ($results) {
return $results->map(function ($row) {
$row['age'] = $row['birth_date']->diff(new DateTime)->y;
return $row;
});
});
Parameters
-
callable|null
$formatter optional -
呼び出し可能なフォーマット。
The formatting callable.
-
int|true
$mode optional -
フォーマッターを上書き、追加、または追加するかどうか。
Whether or not to overwrite, append or prepend the formatter.
Returns
$this
Throws
InvalidArgumentException
from() public ¶
from(mixed $tables, mixed $overwrite)
このクエリのFROM句で使用される単一または複数のテーブルを追加します。
Adds a single or multiple tables to be used in the FROM clause for this query.
テーブルは、文字列の配列、式オブジェクトの配列、単一の式、または単一の文字列として渡すことができます。
Tables can be passed as an array of strings, array of expression objects, a single expression or a single string.
配列が渡される場合、キーは、エイリアスされる実際のフィールドとして値を使用してテーブルをエイリアスするために使用されます。 文字列、ExpressionInterfaceオブジェクト、または他のQueryオブジェクトのエイリアスを作成することもできます。
If an array is passed, keys will be used to alias tables using the value as the real field to be aliased. It is possible to alias strings, ExpressionInterface objects or even other Query objects.
デフォルトでは、2番目の引数がtrueに設定されていない限り、この関数は、渡された引数を選択元のテーブルのリストに追加します。
By default this function will append any passed argument to the list of tables to be selected from, unless the second argument is set to true.
このメソッドは、select、update、およびdeleteステートメントに使用できます。
This method can be used for select, update and delete statements.
Examples:
$query->from(['p' => 'posts']); // Produces FROM posts p
$query->from('authors'); // Appends authors: FROM posts p, authors
$query->from(['products'], true); // Resets the list: FROM products
$query->from(['sub' => $countQuery]); // FROM (SELECT ...) sub
Parameters
-
array|string
$tables optional -
リストに追加するテーブル。 この引数は、文字列の配列、式オブジェクトの配列、または単一の文字列として渡すことができます。 有効なコールタイプについては、上記の例を参照してください。
tables to be added to the list. This argument, can be passed as an array of strings, array of expression objects, or a single string. See the examples above for the valid call types.
-
bool
$overwrite optional -
渡されたリストでテーブルをリセットするかどうか
whether to reset tables with passed list or not
Returns
$this
func() public ¶
func()
任意のSQL関数の生成に使用できる関数ビルダーオブジェクトのインスタンスを返します。
Returns an instance of a functions builder object that can be used for generating arbitrary SQL functions.
Example:
$query->func()->count('*');
$query->func()->dateDiff(['2012-01-05', '2012-01-02'])
Returns
\Cake\Database\FunctionsBuilder
getConnection() public ¶
getConnection()
このクエリの実行と変換に使用される接続インスタンスを取得します。
Gets the connection instance to be used for executing and transforming this query.
Returns
\Cake\Database\Connection
getDefaultTypes() public ¶
getDefaultTypes()
現在の型マップのデフォルトの型を取得します。
Gets default types of current type map.
Returns
array
getEagerLoader() public ¶
getEagerLoader()
現在構成されているインスタンスを返します。
Returns the currently configured instance.
Returns
\Cake\ORM\EagerLoader
getIterator() public ¶
getIterator()
このクエリを実行し、結果イテレータを返します。 この関数はIteratorAggregateインターフェースを実装するために必要であり、execute()を手動で呼び出さなくてもクエリを反復できるため、クエリ自体ではなく結果セットのように見えます。
Executes this query and returns a results iterator. This function is required for implementing the IteratorAggregate interface and allows the query to be iterated without having to call execute() manually, thus making it look like a result set instead of the query itself.
Returns
\Cake\Datasource\ResultSetInterface
getMapReducers() public ¶
getMapReducers()
以前に登録されたマップ削減ルーチンのリストを返します。
Returns the list of previously registered map reduce routines.
Returns
array
getOptions() public ¶
getOptions()
このクエリに適用され、このクラスの別のメソッドでまだ処理されていないカスタムオプションを含む配列を返します。
Returns an array with the custom options that were applied to this query and that were not already processed by another method in this class.
Example:
$query->applyOptions(['doABarrelRoll' => true, 'fields' => ['id', 'name']);
$query->getOptions(); // Returns ['doABarrelRoll' => true]
Returns
array
See Also
このクラスによって処理され、この関数によって返されないオプションについて読む
to read about the options that will be processed by this class and not returned by this function
getRepository() public ¶
getRepository()
このクエリで使用されるデフォルトのテーブルオブジェクト、つまり、from句に表示されるテーブルを返します。
Returns the default table object that will be used by this query, that is, the table that will appear in the from clause.
getResultFormatters() public ¶
getResultFormatters()
以前に登録されたフォーマットルーチンのリストを返します。
Returns the list of previously registered format routines.
Returns
callable[]
getSelectTypeMap() public ¶
getSelectTypeMap()
select句の各フィールドの型が格納されているTypeMapクラスを取得します。
Gets the TypeMap class where the types for each of the fields in the select clause are stored.
Returns
\Cake\Database\TypeMap
getTypeMap() public ¶
getTypeMap()
既存の型マップを返します。
Returns the existing type map.
Returns
\Cake\Database\TypeMap
getValueBinder() public ¶
getValueBinder()
現在使用されているValueBinderインスタンスを返します。
Returns the currently used ValueBinder instance.
ValueBinderは、クエリのプレースホルダーを生成し、それらのプレースホルダーに一時的に値を関連付けて、ステートメントオブジェクトに正しく渡せるようにします。
A ValueBinder is responsible for generating query placeholders and temporarily associate values to those placeholders so that they can be passed correctly to the statement object.
Returns
\Cake\Database\ValueBinder
group() public ¶
group(mixed $fields, mixed $overwrite)
このクエリのGROUP BY句で使用される単一または複数のフィールドを追加します。
Adds a single or multiple fields to be used in the GROUP BY clause for this query.
フィールドは、文字列の配列、式オブジェクトの配列、単一の式、または単一の文字列として渡すことができます。
Fields can be passed as an array of strings, array of expression objects, a single expression or a single string.
デフォルトでは、2番目の引数がtrueに設定されていない限り、この関数は渡された引数をグループ化するフィールドのリストに追加します。
By default this function will append any passed argument to the list of fields to be grouped, unless the second argument is set to true.
Examples:
// Produces GROUP BY id, title
$query->group(['id', 'title']);
// Produces GROUP BY title
$query->group('title');
グループフィールドは、クエリビルダーによってサニタイズされないため、ユーザー指定のデータでの使用には適していません。
Group fields are not suitable for use with user supplied data as they are not sanitized by the query builder.
Parameters
-
array|\Cake\Database\ExpressionInterface|string
$fields -
リストに追加するフィールド
fields to be added to the list
-
bool
$overwrite optional -
渡されたリストでフィールドをリセットするかどうか
whether to reset fields with passed list or not
Returns
$this
groupBy() public ¶
groupBy(string|callable $field)
インメモリは、列の値によってすべての結果をグループ化します。
In-memory group all results by the value of a column.
Parameters
-
string|callable
$field
having() public ¶
having(mixed $conditions, mixed $types, mixed $overwrite)
このクエリのHAVING
句で使用される条件または条件セットを追加します。
このメソッドは、where()
メソッドとまったく同じように動作します。
各パラメーターの使用方法については、そのドキュメントを参照してください。
Adds a condition or set of conditions to be used in theHAVING
clause for this query. This method operates in exactly the same way as the methodwhere()
does. Please refer to its documentation for an insight on how to using each parameter.
フィールドはクエリビルダーによってサニタイズされないため、ユーザーが指定したデータでの使用には適していません。
Having fields are not suitable for use with user supplied data as they are not sanitized by the query builder.
Parameters
-
string|array|\Cake\Database\ExpressionInterface|\Closure|null
$conditions optional -
持っている条件。
The having conditions.
-
array
$types optional -
クエリに値をバインドするために使用されるタイプ名の連想配列
associative array of type names used to bind values to query
-
bool
$overwrite optional -
渡されたリストで条件をリセットするかどうか
whether to reset conditions with passed list or not
Returns
$this
See Also
identifier() public ¶
identifier(string $identifier)
識別子を参照する式を作成します。 識別子を使用してフィールド名を参照し、SQLコンパイラが引用符を適用したり、識別子をエスケープしたりできるようにします。
Creates an expression that refers to an identifier. Identifiers are used to refer to field names and allow the SQL compiler to apply quotes or escape the identifier.
値はそのまま使用されるため、エイリアスを使用するか、識別子にテーブル参照を含める必要がある場合があります。 このメソッドを使用して、SQLメソッドまたは論理ステートメントを挿入しないでください。
The value is used as is, and you might be required to use aliases or include the table reference in the identifier. Do not use this method to inject SQL methods or logical statements.
Example
$query->newExpr()->lte('count', $query->identifier('total'));
Parameters
-
string
$identifier -
式の識別子
The identifier for an expression
Returns
\Cake\Database\ExpressionInterface
indexBy() public ¶
indexBy(string|callable $callback)
列の値で索引付けされた結果を返します。
Returns the results indexed by the value of a column.
Parameters
-
string|callable
$callback
innerJoin() public ¶
innerJoin(mixed $table, mixed $conditions, mixed $types)
クエリに単一のINNER JOIN
句を追加します。
Adds a single INNER JOIN
clause to the query.
これは、join()
を介して結合を作成するための省略メソッドです。
This is a shorthand method for building joins via join()
.
このメソッドの引数は、leftJoin()
省略形と同じです。詳細については、そのメソッドの説明を参照してください。
The arguments of this method are identical to the leftJoin()
shorthand, please refer to that methods description for further details.
Parameters
-
string|array
$table -
結合するテーブル
The table to join with
-
string|array|\Cake\Database\ExpressionInterface
$conditions optional -
参加に使用する条件。
The conditions to use for joining.
-
array
$types optional -
値を対応するデータベース表現に変換するために使用される条件に関連付けられたタイプのリスト。
a list of types associated to the conditions used for converting values to the corresponding database representation.
Returns
$this
innerJoinWith() public ¶
innerJoinWith(string $assoc, ?callable $builder)
渡された関連付けテーブルを使用してINNER JOINを作成しますが、外部キーの一致と、最初に設定されたカスタム条件を保持します。
Creates an INNER JOIN with the passed association table while preserving the foreign key matching and the custom conditions that were originally set for it.
この関数は、contain
グラフにエントリを追加します。
This function will add entries in the contain
graph.
Example:
// Bring only articles that were tagged with 'cake'
$query->innerJoinWith('Tags', function ($q) {
return $q->where(['name' => 'cake']);
);
これにより、次のSQLが作成されます:
This will create the following SQL:
SELECT Articles.*
FROM articles Articles
INNER JOIN tags Tags ON Tags.name = 'cake'
INNER JOIN articles_tags ArticlesTags ON ArticlesTags.tag_id = Tags.id
AND ArticlesTags.articles_id = Articles.id
この関数はmatching()
と同じように機能しますが、関連付けからフィールドを選択しない点が異なります。
This function works the same as matching()
with the difference that it will select no fields from the association.
Parameters
-
string
$assoc -
参加する協会
The association to join with
-
callable|null
$builder optional -
カスタム条件の追加や一部のフィールドの選択に使用できる、事前に作成されたクエリオブジェクトを受け取る関数
a function that will receive a pre-made query object that can be used to add custom conditions or selecting some fields
Returns
$this
See Also
insert() public ¶
insert(array $columns, array $types)
挿入クエリを作成します。
Create an insert query.
これにより、クエリタイプが「挿入」に変更されます。 このメソッドを呼び出すと、Query::values()で以前に設定されたデータがリセットされます。
This changes the query type to be 'insert'. Note calling this method will reset any data previously set with Query::values()
where()メソッドと組み合わせて、削除クエリを作成できます。
Can be combined with the where() method to create delete queries.
Parameters
-
array
$columns -
挿入する列。
The columns to insert into.
-
array
$types optional -
列とそのデータ型の間のマップ。
A map between columns & their datatypes.
Returns
$this
into() public ¶
into(string $table)
挿入クエリのテーブル名を設定します。
Set the table name for insert queries.
Parameters
-
string
$table -
挿入するテーブル名。
The table name to insert into.
Returns
$this
isAutoFieldsEnabled() public ¶
isAutoFieldsEnabled()
ORMがフィールドを自動的に追加するかどうかを取得します。
Gets whether or not the ORM should automatically append fields.
デフォルトでは、select()を呼び出すと自動フィールドが無効になります。 自動フィールドはenableAutoFields()で再度有効にできます。
By default calling select() will disable auto-fields. You can re-enable auto-fields with enableAutoFields().
Returns
bool|null
現在の値。 まだ有効でも無効でもない場合はnullを返します。
The current value. Returns null if neither enabled or disabled yet.
isBufferedResultsEnabled() public ¶
isBufferedResultsEnabled()
バッファリングされた結果が有効か無効かを返します。
Returns whether buffered results are enabled/disabled.
有効にすると、このクエリによって返される結果がバッファされます。 これにより、結果セットを複数回反復したり、キャッシュと反復の両方を行うことができます。
When enabled the results returned by this Query will be buffered. This enables you to iterate a result set multiple times, or both cache and iterate it.
無効にすると、フェッチした結果が今後の反復で記憶されなくなるため、メモリ消費が少なくなります。
When disabled it will consume less memory as fetched results are not remembered for future iterations.
Returns
bool
isEagerLoaded() public ¶
isEagerLoaded()
現在構成されているクエリの_eagerLoaded
値を返します
Returns the current configured query _eagerLoaded
value
Returns
bool
isEmpty() public ¶
isEmpty()
このクエリで結果が見つからなかった場合はtrueを返します。
Returns true if this query found no results.
isHydrationEnabled() public ¶
isHydrationEnabled()
現在のハイドレーションモードを返します。
Returns the current hydration mode.
Returns
bool
join() public ¶
join(mixed $tables, mixed $types, mixed $overwrite)
JOIN句として使用する単一または複数のテーブルをこのクエリに追加します。
Adds a single or multiple tables to be used as JOIN clauses to this query.
テーブルは、文字列の配列、結合部分を説明する配列、複数の結合説明を含む配列、または単一の文字列として渡すことができます。
Tables can be passed as an array of strings, an array describing the join parts, an array with multiple join descriptions, or a single string.
デフォルトでは、この関数は、3番目の引数がtrueに設定されていない限り、結合されるテーブルのリストに渡された引数を追加します。
By default this function will append any passed argument to the list of tables to be joined, unless the third argument is set to true.
結合タイプが指定されていない場合、デフォルトでINNER JOIN
が使用されます。$query->join(['authors'])
は、INNER JOIN authors ON 1 = 1
を生成します
When no join type is specified anINNER JOIN
is used by default:$query->join(['authors'])
will produceINNER JOIN authors ON 1 = 1
配列キーを使用して結合のエイリアスを作成することもできます。$query->join(['a' => 'authors'])
は、INNER JOIN authors a ON 1 = 1
It is also possible to alias joins using the array key:$query->join(['a' => 'authors'])
will produceINNER JOIN authors a ON 1 = 1
配列表記を使用して、結合を完全に記述し、エイリアスを付けることができます。
A join can be fully described and aliased using the array notation:
$query->join([
'a' => [
'table' => 'authors',
'type' => 'LEFT',
'conditions' => 'a.id = b.author_id'
]
]);
// Produces LEFT JOIN authors a ON a.id = b.author_id
完全な説明を含め、配列で複数の結合を指定することもできます。
You can even specify multiple joins in an array, including the full description:
$query->join([
'a' => [
'table' => 'authors',
'type' => 'LEFT',
'conditions' => 'a.id = b.author_id'
],
'p' => [
'table' => 'publishers',
'type' => 'INNER',
'conditions' => 'p.id = b.publisher_id AND p.name = "Cake Software Foundation"'
]
]);
// LEFT JOIN authors a ON a.id = b.author_id
// INNER JOIN publishers p ON p.id = b.publisher_id AND p.name = "Cake Software Foundation"
条件とタイプの使用
Using conditions and types
条件は、上記の例のように、列を比較するための文字列、またはすでに引用されているリテラル値を持つ文字列を使用して表現できます。 さらに、配列または式オブジェクトで表現された条件を使用することが可能です。
Conditions can be expressed, as in the examples above, using a string for comparing columns, or string with already quoted literal values. Additionally it is possible to use conditions expressed in arrays or expression objects.
条件を表現するために配列を使用する場合、リテラル値を正しいデータベース表現に変換することが望ましい場合がよくあります。 これは、この関数の2番目のパラメーターを使用して実現されます。
When using arrays for expressing conditions, it is often desirable to convert the literal values to the correct database representation. This is achieved using the second parameter of this function.
$query->join(['a' => [
'table' => 'articles',
'conditions' => [
'a.posted >=' => new DateTime('-3 days'),
'a.published' => true,
'a.author_id = authors.id'
]
]], ['a.posted' => 'datetime', 'a.published' => 'boolean'])
結合の上書き
Overwriting joins
配列表記を使用してエイリアス結合を作成する場合、この関数への後続の呼び出しで同じエイリアスを使用して以前の結合定義をオーバーライドできます。または、この関数の3番目のパラメーターがtrueに設定されている場合は、以前に定義されたすべての結合を別のリストに置き換えることができます。
When creating aliased joins using the array notation, you can override previous join definitions by using the same alias in consequent calls to this function or you can replace all previously defined joins with another list if the third parameter for this function is set to true.
$query->join(['alias' => 'table']); // joins table with as alias
$query->join(['alias' => 'another_table']); // joins another_table with as alias
$query->join(['something' => 'different_table'], [], true); // resets joins list
Parameters
-
array|string
$tables -
クエリで結合されるテーブルのリスト
list of tables to be joined in the query
-
array
$types optional -
クエリに値をバインドするために使用されるタイプ名の連想配列
associative array of type names used to bind values to query
-
bool
$overwrite optional -
渡されたリストで結合をリセットするかどうか
whether to reset joins with passed list or not
Returns
$this
See Also
jsonSerialize() public ¶
jsonSerialize()
クエリを実行し、結果セットをJSONに変換します。
Executes the query and converts the result set into JSON.
JsonSerializableインターフェースの一部。
Part of JsonSerializable interface.
Returns
\Cake\Datasource\ResultSetInterface
JSONに変換するデータ。
The data to convert to JSON.
leftJoin() public ¶
leftJoin(mixed $table, mixed $conditions, mixed $types)
クエリに単一のLEFT JOIN
句を追加します。
Adds a single LEFT JOIN
clause to the query.
これは、join()
を介して結合を作成するための省略メソッドです。
This is a shorthand method for building joins via join()
.
テーブル名は、文字列として、またはエイリアスが必要な場合は配列として渡すことができます:
The table name can be passed as a string, or as an array in case it needs to be aliased:
// LEFT JOIN authors ON authors.id = posts.author_id
$query->leftJoin('authors', 'authors.id = posts.author_id');
// LEFT JOIN authors a ON a.id = posts.author_id
$query->leftJoin(['a' => 'authors'], 'a.id = posts.author_id');
条件は、文字列、配列、または式オブジェクトとして渡すことができます。
配列を使用する場合、値を変換する方法を定義するために$types
パラメーターと組み合わせることができます。
Conditions can be passed as strings, arrays, or expression objects.
When using arrays it is possible to combine them with the $types
parameter in order to define how to convert the values:
$query->leftJoin(['a' => 'articles'], [
'a.posted >=' => new DateTime('-3 days'),
'a.published' => true,
'a.author_id = authors.id'
], ['a.posted' => 'datetime', 'a.published' => 'boolean']);
条件とタイプの詳細については、join()
を参照してください。
See join()
for further details on conditions and types.
Parameters
-
string|string[]
$table -
結合するテーブル
The table to join with
-
string|array|\Cake\Database\ExpressionInterface
$conditions optional -
参加に使用する条件。
The conditions to use for joining.
-
array
$types optional -
値を対応するデータベース表現に変換するために使用される条件に関連付けられたタイプのリスト。
a list of types associated to the conditions used for converting values to the corresponding database representation.
Returns
$this
leftJoinWith() public ¶
leftJoinWith(string $assoc, ?callable $builder)
渡された関連付けテーブルを使用してLEFT JOINを作成しますが、外部キーの一致と、最初に設定されたカスタム条件を保持します。
Creates a LEFT JOIN with the passed association table while preserving the foreign key matching and the custom conditions that were originally set for it.
この関数は、contain
グラフにエントリを追加します。
This function will add entries in the contain
graph.
Example:
// Get the count of articles per user
$usersQuery
->select(['total_articles' => $query->func()->count('Articles.id')])
->leftJoinWith('Articles')
->group(['Users.id'])
->enableAutoFields();
LEFT JOINに渡される条件をカスタマイズすることもできます:
You can also customize the conditions passed to the LEFT JOIN:
// Get the count of articles per user with at least 5 votes
$usersQuery
->select(['total_articles' => $query->func()->count('Articles.id')])
->leftJoinWith('Articles', function ($q) {
return $q->where(['Articles.votes >=' => 5]);
})
->group(['Users.id'])
->enableAutoFields();
これにより、次のSQLが作成されます:
This will create the following SQL:
SELECT COUNT(Articles.id) AS total_articles, Users.*
FROM users Users
LEFT JOIN articles Articles ON Articles.user_id = Users.id AND Articles.votes >= 5
GROUP BY USers.id
ドット表記を使用することで、深い関連付けを残して結合することができます。
It is possible to left join deep associations by using dot notation
Example:
// Total comments in articles by 'markstory'
$query
->select(['total_comments' => $query->func()->count('Comments.id')])
->leftJoinWith('Comments.Users', function ($q) {
return $q->where(['username' => 'markstory']);
)
->group(['Users.id']);
クロージャーに渡されるクエリは、select
、where
、andWhere
、orWhere
の呼び出しのみを受け入れることに注意してください。
より複雑な句を追加する場合は、メインクエリで直接行うことができます。
Please note that the query passed to the closure will only accept callingselect
,where
,andWhere
andorWhere
on it. If you wish to add more complex clauses you can do it directly in the main query.
Parameters
-
string
$assoc -
参加する協会
The association to join with
-
callable|null
$builder optional -
カスタム条件の追加や一部のフィールドの選択に使用できる、事前に作成されたクエリオブジェクトを受け取る関数
a function that will receive a pre-made query object that can be used to add custom conditions or selecting some fields
Returns
$this
limit() public ¶
limit(mixed $num)
データベースから取得するレコードの数を設定し、整数または整数に評価される式オブジェクトを受け入れます。
Sets the number of records that should be retrieved from database, accepts an integer or an expression object that evaluates to an integer.
一部のデータベースでは、この操作がサポートされていないか、結果セットのサイズを制限するためにクエリを変換する必要があります。
In some databases, this operation might not be supported or will require the query to be transformed in order to limit the result set size.
Examples
$query->limit(10) // generates LIMIT 10
$query->limit($query->newExpr()->add(['1 + 1'])); // LIMIT (1 + 1)
Parameters
-
int|\Cake\Database\ExpressionInterface|null
$num -
返されるレコードの数
number of records to be returned
Returns
$this
map() public ¶
map(callable $c)
callableを使用して各結果を変更します
Modifies each of the results using the callable
Parameters
-
callable
$c
mapReduce() public ¶
mapReduce(?callable $mapper, ?callable $reducer, bool $overwrite)
データベース結果の上で実行される新しいMapReduceルーチンを登録します。マッパーと呼び出し元の両方の呼び出し可能オブジェクトは、呼び出し可能なオブジェクトである必要があります。
Register a new MapReduce routine to be executed on top of the database results Both the mapper and caller callable should be invokable objects.
MapReduceルーティングは、クエリが実行され、最初の結果がフェッチされるときにのみ実行されます。
The MapReduce routing will only be run when the query is executed and the first result is attempted to be fetched.
3番目の引数がtrueに設定されている場合、以前のマップリデューサーが消去され、渡された引数に置き換えられます。
If the third argument is set to true, it will erase previous map reducers and replace it with the arguments passed.
Parameters
-
callable|null
$mapper optional -
マッパーは呼び出し可能です。
The mapper callable.
-
callable|null
$reducer optional -
還元機能。
The reducing function.
-
bool
$overwrite optional -
既存のマップ+リデュース関数を上書きするには、trueに設定します。
Set to true to overwrite existing map + reduce functions.
Returns
$this
See Also
マップレデューサーへのエミットデータの使用方法の詳細については。
for details on how to use emit data to the map reducer.
matching() public ¶
matching(string $assoc, ?callable $builder)
このクエリにフィルター条件を追加して、関連付けられたテーブルの条件に基づいて、関連付けられたテーブルから別のテーブルとの関係を持つ行のみを取得します。
Adds filtering conditions to this query to only bring rows that have a relation to another from an associated table, based on conditions in the associated table.
この関数は、contain
グラフにエントリを追加します。
This function will add entries in the contain
graph.
Example:
// Bring only articles that were tagged with 'cake'
$query->matching('Tags', function ($q) {
return $q->where(['name' => 'cake']);
);
ドット表記を使用して、深い関連付けでフィルタリングできます。
It is possible to filter by deep associations by using dot notation:
Example:
// Bring only articles that were commented by 'markstory'
$query->matching('Comments.Users', function ($q) {
return $q->where(['username' => 'markstory']);
);
この関数はINNER JOIN
を作成するため、条件によってフィルターされていない場合は重複行が取得される可能性があるため、このクエリでdistinct
を呼び出すことを検討する必要があります。
これは、たとえば、同じユーザーが同じ記事で複数回コメントした場合などです。
As this function will createINNER JOIN
, you might want to consider callingdistinct
on this query as you might get duplicate rows if your conditions don't filter them already. This might be the case, for example, of the same user commenting more than once in the same article.
Example:
// Bring unique articles that were commented by 'markstory'
$query->distinct(['Articles.id'])
->matching('Comments.Users', function ($q) {
return $q->where(['username' => 'markstory']);
);
クロージャーに渡されるクエリは、select
、where
、andWhere
、orWhere
の呼び出しのみを受け入れることに注意してください。
より複雑な句を追加する場合は、メインクエリで直接行うことができます。
Please note that the query passed to the closure will only accept callingselect
,where
,andWhere
andorWhere
on it. If you wish to add more complex clauses you can do it directly in the main query.
Parameters
-
string
$assoc -
フィルタリングする関連
The association to filter by
-
callable|null
$builder optional -
カスタム条件の追加や一部のフィールドの選択に使用できる、事前に作成されたクエリオブジェクトを受け取る関数
a function that will receive a pre-made query object that can be used to add custom conditions or selecting some fields
Returns
$this
max() public ¶
max(mixed $field, int $type)
すべての結果の1つの列の最大値を返します。
Returns the maximum value for a single column in all the results.
Parameters
-
mixed
$field -
int
$type
min() public ¶
min(mixed $field, int $type)
すべての結果の1つの列の最小値を返します。
Returns the minimum value for a single column in all the results.
Parameters
-
mixed
$field -
int
$type
modifier() public ¶
modifier(mixed $modifiers, mixed $overwrite)
SELECT
で使用する単一または複数のSELECT
修飾子を追加します。
Adds a single or multipleSELECT
modifiers to be used in theSELECT
.
デフォルトでは、この関数は、2番目の引数がtrueに設定されていない限り、適用される修飾子のリストに渡された引数を追加します。
By default this function will append any passed argument to the list of modifiers to be applied, unless the second argument is set to true.
Example:
// Ignore cache query in MySQL
$query->select(['name', 'city'])->from('products')->modifier('SQL_NO_CACHE');
// It will produce the SQL: SELECT SQL_NO_CACHE name, city FROM products
// Or with multiple modifiers
$query->select(['name', 'city'])->from('products')->modifier(['HIGH_PRIORITY', 'SQL_NO_CACHE']);
// It will produce the SQL: SELECT HIGH_PRIORITY SQL_NO_CACHE name, city FROM products
Parameters
-
array|\Cake\Database\ExpressionInterface|string
$modifiers -
クエリに適用される修飾子
modifiers to be applied to the query
-
bool
$overwrite optional -
フィールドリストを使用して順序をリセットするかどうか
whether to reset order with field list or not
Returns
$this
nest() public ¶
nest(mixed $k, mixed $p, mixed $n)
$nをネストキーとして使用して、$kの同じ値を持つ列$pの値をネストしてツリー構造を作成します。
Creates a tree structure by nesting the values of column $p into that with the same value for $k using $n as the nesting key.
Parameters
-
mixed
$k -
mixed
$p -
mixed
$n
newExpr() public ¶
newExpr(mixed $rawExpression)
新しいQueryExpressionオブジェクトを返します。 これは、流れるようなインターフェイスを使用して複雑なクエリを作成するときに便利な機能です。 必要に応じて、サブクラスでこの関数をオーバーライドして、より専門的なQueryExpressionクラスを使用することもできます。
Returns a new QueryExpression object. This is a handy function when building complex queries using a fluent interface. You can also override this function in subclasses to use a more specialized QueryExpression class if required.
オプションで、\Cake\Database\Expression\QueryExpressionで受け入れられる任意の形式の単一の生SQL文字列または配列または式を渡すことができます。
You can optionally pass a single raw SQL string or an array or expressions in any format accepted by \Cake\Database\Expression\QueryExpression:
$expression = $query->newExpr(); // Returns an empty expression object
$expression = $query->newExpr('Table.column = Table2.column'); // Return a raw SQL expression
Parameters
-
string|array|\Cake\Database\ExpressionInterface|null
$rawExpression optional -
文字列、配列、または式オブジェクトでラップしたいもの
A string, array or anything you want wrapped in an expression object
Returns
\Cake\Database\Expression\QueryExpression
notMatching() public ¶
notMatching(string $assoc, ?callable $builder)
このクエリにフィルタリング条件を追加して、関連付けられたテーブルの条件に基づいて、関連付けられたテーブルから別のものと一致しない行のみを取得します。
Adds filtering conditions to this query to only bring rows that have no match to another from an associated table, based on conditions in the associated table.
この関数は、contain
グラフにエントリを追加します。
This function will add entries in the contain
graph.
Example:
// Bring only articles that were not tagged with 'cake'
$query->notMatching('Tags', function ($q) {
return $q->where(['name' => 'cake']);
);
ドット表記を使用して、深い関連付けでフィルタリングできます。
It is possible to filter by deep associations by using dot notation:
Example:
// Bring only articles that weren't commented by 'markstory'
$query->notMatching('Comments.Users', function ($q) {
return $q->where(['username' => 'markstory']);
);
この関数はLEFT JOIN
を作成するため、条件でフィルターされていない場合に重複行が取得される可能性があるため、このクエリでdistinct
を呼び出すことを検討してください。
これは、たとえば、同じ記事に複数のコメントがある場合などです。
As this function will create aLEFT JOIN
, you might want to consider callingdistinct
on this query as you might get duplicate rows if your conditions don't filter them already. This might be the case, for example, of the same article having multiple comments.
Example:
// Bring unique articles that were commented by 'markstory'
$query->distinct(['Articles.id'])
->notMatching('Comments.Users', function ($q) {
return $q->where(['username' => 'markstory']);
);
クロージャーに渡されるクエリは、select
、where
、andWhere
、orWhere
の呼び出しのみを受け入れることに注意してください。
より複雑な句を追加する場合は、メインクエリで直接行うことができます。
Please note that the query passed to the closure will only accept callingselect
,where
,andWhere
andorWhere
on it. If you wish to add more complex clauses you can do it directly in the main query.
Parameters
-
string
$assoc -
フィルタリングする関連
The association to filter by
-
callable|null
$builder optional -
カスタム条件の追加や一部のフィールドの選択に使用できる、事前に作成されたクエリオブジェクトを受け取る関数
a function that will receive a pre-made query object that can be used to add custom conditions or selecting some fields
Returns
$this
offset() public ¶
offset(mixed $num)
元の結果セットからスキップするレコードの数を設定します。これは通常、大きな結果のページ付けに使用されます。 整数または整数に評価される式オブジェクトを受け入れます。
Sets the number of records that should be skipped from the original result set This is commonly used for paginating large results. Accepts an integer or an expression object that evaluates to an integer.
一部のデータベースでは、この操作がサポートされていないか、結果セットのサイズを制限するためにクエリを変換する必要があります。
In some databases, this operation might not be supported or will require the query to be transformed in order to limit the result set size.
Examples
$query->offset(10) // generates OFFSET 10
$query->offset($query->newExpr()->add(['1 + 1'])); // OFFSET (1 + 1)
Parameters
-
int|\Cake\Database\ExpressionInterface|null
$num -
スキップするレコードの数
number of records to be skipped
Returns
$this
order() public ¶
order(mixed $fields, mixed $overwrite)
このクエリのORDER句で使用される単一または複数のフィールドを追加します。
Adds a single or multiple fields to be used in the ORDER clause for this query.
フィールドは、文字列の配列、式オブジェクトの配列、単一の式、または単一の文字列として渡すことができます。
Fields can be passed as an array of strings, array of expression objects, a single expression or a single string.
配列が渡される場合、キーはフィールド自体として使用され、値はそのようなフィールドが順序付けられる順序を表します。 同じフィールドをキーとして複数回呼び出すと、最後の注文定義が他の注文より優先されます。
If an array is passed, keys will be used as the field itself and the value will represent the order in which such field should be ordered. When called multiple times with the same fields as key, the last order definition will prevail over the others.
デフォルトでは、この関数は、2番目の引数がtrueに設定されていない限り、渡される引数を選択されるフィールドのリストに追加します。
By default this function will append any passed argument to the list of fields to be selected, unless the second argument is set to true.
Examples:
$query->order(['title' => 'DESC', 'author_id' => 'ASC']);
生成する:
Produces:
ORDER BY title DESC, author_id ASC
$query->order(['title' => 'DESC NULLS FIRST'])->order('author_id');
生成されます:
Will generate:
ORDER BY title DESC NULLS FIRST, author_id
$expression = $query->newExpr()->add(['id % 2 = 0']);
$query->order($expression)->order(['title' => 'ASC']);
となります:
Will become:
ORDER BY (id %2 = 0), title ASC
複雑な式を順序条件として設定する必要がある場合は、orderAsc()
またはorderDesc()
を使用する必要があります。
If you need to set complex expressions as order conditions, you should useorderAsc()
ororderDesc()
.
Parameters
-
array|\Cake\Database\ExpressionInterface|\Closure|string
$fields -
リストに追加するフィールド
fields to be added to the list
-
bool
$overwrite optional -
フィールドリストを使用して順序をリセットするかどうか
whether to reset order with field list or not
Returns
$this
orderAsc() public ¶
orderAsc(mixed $field, mixed $overwrite)
ASC方向のORDER BY句を追加します。
Add an ORDER BY clause with an ASC direction.
このメソッドを使用すると、order()とは異なり、複雑な式を順序条件として設定できます
This method allows you to set complex expressions as order conditions unlike order()
オーダーフィールドは、クエリビルダーによってサニタイズされないため、ユーザー指定のデータでの使用には適していません。
Order fields are not suitable for use with user supplied data as they are not sanitized by the query builder.
Parameters
-
string|\Cake\Database\Expression\QueryExpression
$field -
注文するフィールド。
The field to order on.
-
bool
$overwrite optional -
順序句をリセットするかどうか。
Whether or not to reset the order clauses.
Returns
$this
orderDesc() public ¶
orderDesc(mixed $field, mixed $overwrite)
DESC方向を指定したORDER BY句を追加します。
Add an ORDER BY clause with a DESC direction.
このメソッドを使用すると、order()とは異なり、複雑な式を順序条件として設定できます
This method allows you to set complex expressions as order conditions unlike order()
オーダーフィールドは、クエリビルダーによってサニタイズされないため、ユーザー指定のデータでの使用には適していません。
Order fields are not suitable for use with user supplied data as they are not sanitized by the query builder.
Parameters
-
string|\Cake\Database\Expression\QueryExpression
$field -
注文するフィールド。
The field to order on.
-
bool
$overwrite optional -
順序句をリセットするかどうか。
Whether or not to reset the order clauses.
Returns
$this
page() public ¶
page(int $num, ?int $limit)
必要な結果のページを設定します。
Set the page of results you want.
このメソッドは、結果として必要なレコードセットに制限+オフセットを設定するための使いやすいインターフェイスを提供します。
空の場合、制限は既存の制限句にデフォルト設定され、それも空の場合、25
が使用されます。
This method provides an easier to use interface to set the limit + offset in the record set you want as results.
If empty the limit will default to the existing limit clause, and if that too is empty, then 25
will be used.
ページは1から開始する必要があります。
Pages must start at 1.
Parameters
-
int
$num -
必要なページ番号。
The page number you want.
-
int|null
$limit optional -
ページに必要な行数。 nullの場合、現在の制限句が使用されます。
The number of rows you want in the page. If null the current limit clause will be used.
Returns
$this
Throws
InvalidArgumentException
ページ番号 < 1の場合。
If page number < 1.
reduce() public ¶
reduce(callable $c, mixed $zero)
callableを使用して、すべての結果を単一の値に折りたたみます。
Folds all the results into a single value using the callable.
Parameters
-
callable
$c -
mixed
$zero
reject() public ¶
reject(callable $c)
呼び出し可能テストに合格した結果を削除します
Removes the results passing the callable test
Parameters
-
callable
$c
removeJoin() public ¶
removeJoin(string $name)
結合が定義されている場合は削除します。
Remove a join if it has been defined.
結合を再定義する場合、または結合句の順序を変更する場合に役立ちます。
Useful when you are redefining joins or want to re-order the join clauses.
Parameters
-
string
$name -
削除する結合のエイリアス/名前。
The alias/name of the join to remove.
Returns
$this
repository() public ¶
repository(\Cake\Datasource\RepositoryInterface $table)
このクエリで使用されるデフォルトのTableオブジェクトを設定し、FROM
句を形成します。
Set the default Table object that will be used by this query and form the FROM
clause.
Parameters
-
\Cake\Datasource\RepositoryInterface|\Cake\ORM\Table
$table -
使用するデフォルトのテーブルオブジェクト
The default table object to use
Returns
$this
rightJoin() public ¶
rightJoin(mixed $table, mixed $conditions, mixed $types)
クエリに単一のRIGHT JOIN
句を追加します。
Adds a single RIGHT JOIN
clause to the query.
これは、join()
を介して結合を作成するための省略メソッドです。
This is a shorthand method for building joins via join()
.
このメソッドの引数は、leftJoin()
省略形と同じです。詳細については、そのメソッドの説明を参照してください。
The arguments of this method are identical to the leftJoin()
shorthand, please refer to that methods description for further details.
Parameters
-
string|string[]
$table -
結合するテーブル
The table to join with
-
string|array|\Cake\Database\ExpressionInterface
$conditions optional -
参加に使用する条件。
The conditions to use for joining.
-
array
$types optional -
値を対応するデータベース表現に変換するために使用される条件に関連付けられたタイプのリスト。
a list of types associated to the conditions used for converting values to the corresponding database representation.
Returns
$this
rowCountAndClose() public ¶
rowCountAndClose()
このクエリのSQLを実行し、変更されたレコードの行数を返す前にステートメントをすぐに閉じます。
Executes the SQL of this query and immediately closes the statement before returning the row count of records changed.
このメソッドはUPDATEおよびDELETEクエリで使用できますが、SELECTクエリにはお勧めできません。レコードのカウントには使用されません。
This method can be used with UPDATE and DELETE queries, but is not recommended for SELECT queries and is not used to count records.
Example
$rowCount = $query->update('articles')
->set(['published'=>true])
->where(['published'=>false])
->rowCountAndClose();
上記の例では、すべての偽のレコードに対してパブリッシュされた列を真に変更し、更新されたレコードの数を返します。
The above example will change the published column to true for all false records, and return the number of records that were updated.
Returns
int
sample() public ¶
sample(int $size = 10)
インメモリは結果をシャッフルし、それらのサブセットを返します。
In-memory shuffle the results and return a subset of them.
Parameters
-
int
$size = 10
select() public ¶
select(mixed $fields, bool $overwrite)
このクエリが実行されたときに、SELECT
ステートメントによって返される新しいフィールドを追加します。
フィールドは、文字列の配列、式オブジェクトの配列、単一の式、または単一の文字列として渡すことができます。
Adds new fields to be returned by a SELECT
statement when this query is executed.
Fields can be passed as an array of strings, array of expression objects, a single expression or a single string.
配列が渡される場合、キーは、エイリアスされる実際のフィールドとして値を使用してフィールドをエイリアスするために使用されます。 文字列、Expressionオブジェクト、さらには他のQueryオブジェクトにもエイリアスを設定できます。
If an array is passed, keys will be used to alias fields using the value as the real field to be aliased. It is possible to alias strings, Expression objects or even other Query objects.
呼び出し可能な関数が渡された場合、関数の戻り配列がフィールドのリストとして使用されます。
If a callable function is passed, the returning array of the function will be used as the list of fields.
デフォルトでは、この関数は、2番目の引数がtrueに設定されていない限り、渡された引数を選択されるフィールドのリストに追加します。
By default this function will append any passed argument to the list of fields to be selected, unless the second argument is set to true.
Examples:
$query->select(['id', 'title']); // Produces SELECT id, title
$query->select(['author' => 'author_id']); // Appends author: SELECT id, title, author_id as author
$query->select('id', true); // Resets the list: SELECT id
$query->select(['total' => $countQuery]); // SELECT id, (SELECT ...) AS total
$query->select(function ($query) {
return ['article_id', 'total' => $query->count('*')];
})
デフォルトではフィールドは選択されていません。Cake\ORM\Query
のインスタンスがあり、フィールドを追加しようとする場合は、Cake\ORM\Query::enableAutoFields()
を呼び出して、テーブルからデフォルトのフィールドを選択する必要もあります。
By default no fields are selected, if you have an instance ofCake\ORM\Query
and try to append fields you should also callCake\ORM\Query::enableAutoFields()
to select the default fields from the table.
Cake\ORM\Table
またはCake\ORM\Association
クラスのインスタンスを渡すと、テーブルまたは関連付けのスキーマ内のすべてのフィールドがselect句に追加されます。
If you pass an instance of aCake\ORM\Table
orCake\ORM\Association
class, all the fields in the schema of the table or the association will be added to the select clause.
Parameters
-
array|\Cake\Database\ExpressionInterface|callable|string|\Cake\ORM\Table|\Cake\ORM\Association
$fields optional -
リストに追加するフィールド。
Fields to be added to the list.
-
bool
$overwrite optional -
渡されたリストでフィールドをリセットするかどうか
whether to reset fields with passed list or not
Returns
$this
selectAllExcept() public ¶
selectAllExcept(mixed $table, array $excludedFields, bool $overwrite)
除外されたフィールドを除く、渡されたテーブルに関連付けられたすべてのフィールドがクエリの選択句に追加されます。 渡された除外フィールドにはエイリアスを設定しないでください。
All the fields associated with the passed table except the excluded fields will be added to the select clause of the query. Passed excluded fields should not be aliased.
このメソッドへの最初の呼び出しの後、2番目の呼び出しを使用して、最初の呼び出しによって既にクエリに追加されているフィールドを削除することはできません。 最初の呼び出しの後にリストを変更する必要がある場合は、overpass boolean trueを使用して、select句をリセットし、以前のすべての追加を削除します。
After the first call to this method, a second call cannot be used to remove fields that have already been added to the query by the first. If you need to change the list after the first call, pass overwrite boolean true which will reset the select clause removing all previous additions.
Parameters
-
\Cake\ORM\Table|\Cake\ORM\Association
$table -
列の配列を取得するために使用するテーブル
The table to use to get an array of columns
-
string[]
$excludedFields -
$tableから選択したくないエイリアスされていない列名
The un-aliased column names you do not want selected from $table
-
bool
$overwrite optional -
以前に選択したフィールドをリセット/削除するかどうか
Whether to reset/remove previous selected fields
Returns
$this
Throws
InvalidArgumentException
Association | Tableが最初の引数で渡されない場合
If Association|Table is not passed in first argument
set() public ¶
set(mixed $key, mixed $value, mixed $types)
更新する1つまたは複数のフィールドを設定します。
Set one or many fields to update.
Examples
文字列を渡す:
Passing a string:
$query->update('articles')->set('title', 'The Title');
配列を渡す:
Passing an array:
$query->update('articles')->set(['title' => 'The Title'], ['title' => 'string']);
呼び出し可能オブジェクトを渡す:
Passing a callable:
$query->update('articles')->set(function ($exp) {
return $exp->eq('title', 'The title', 'string');
});
Parameters
-
string|array|\Closure|\Cake\Database\Expression\QueryExpression
$key -
列名またはキーの配列
The column name or array of keys
-
設定する値。
これは、SQLフラグメントを含むQueryExpressionにすることもできます。 また、式オブジェクトを返すために必要なクロージャーにすることもできます。
values to set. This can also be a QueryExpression containing a SQL fragment. It can also be a Closure, that is required to return an expression object.
-
設定する値。
これは、SQLフラグメントを含むQueryExpressionにすることもできます。 また、式オブジェクトを返すために必要なクロージャーにすることもできます。
-
mixed
$value optional -
$keyを更新する値。 $keyが配列またはQueryExpressionの場合はnullにできます。 $keyが配列の場合、このパラメーターは代わりに$typesとして使用されます。
The value to update $key to. Can be null if $key is an array or QueryExpression. When $key is an array, this parameter will be used as $types instead.
-
array|string
$types optional -
データを扱う列のタイプ。
The column types to treat data as.
Returns
$this
setConnection() public ¶
setConnection(\Cake\Database\Connection $connection)
このクエリの実行と変換に使用される接続インスタンスを設定します。
Sets the connection instance to be used for executing and transforming this query.
Parameters
-
\Cake\Database\Connection
$connection -
接続インスタンス
Connection instance
Returns
$this
setDefaultTypes() public ¶
setDefaultTypes(array $types)
実装オブジェクトのフィールドのデフォルトの型マッピングを上書きします。
Overwrite the default type mappings for fields in the implementing object.
このメソッドは、クエリ内の複数の関数/式で共有される型マッピングを設定する必要がある場合に役立ちます。
This method is useful if you need to set type mappings that are shared across multiple functions/expressions in a query.
既存のものを上書きせずにデフォルトを追加するには、getTypeMap()->addDefaults()
を使用します
To add a default without overwriting existing ones use getTypeMap()->addDefaults()
Parameters
-
array
$types -
設定するタイプの配列。
The array of types to set.
Returns
$this
See Also
setEagerLoader() public ¶
setEagerLoader(\Cake\ORM\EagerLoader $instance)
アソシエーションのロードと格納の格納に使用する熱心なローダークラスのインスタンスを設定します。
Sets the instance of the eager loader class to use for loading associations and storing containments.
Parameters
-
\Cake\ORM\EagerLoader
$instance -
使用する熱心なローダー。
The eager loader to use.
Returns
$this
setResult() public ¶
setResult(iterable $results)
クエリの結果セットを設定します。
Set the result set for a query.
クエリの結果セットを設定すると、execute()は何もしません。 SQLクエリを実行して結果をフェッチする代わりに、このメソッドに提供されたResultSetが返されます。
Setting the resultset of a query will make execute() a no-op. Instead of executing the SQL query and fetching results, the ResultSet provided to this method will be returned.
この方法は、永続キャッシュに保存された結果と組み合わせると最も役立ちます。
This method is most useful when combined with results stored in a persistent cache.
Parameters
-
iterable
$results -
このクエリが返す結果。
The results this query should return.
Returns
$this
setSelectTypeMap() public ¶
setSelectTypeMap(\Cake\Database\TypeMap $typeMap)
Select句の各フィールドの型が格納されるTypeMapクラスを設定します。
Sets the TypeMap class where the types for each of the fields in the select clause are stored.
Parameters
-
\Cake\Database\TypeMap
$typeMap -
使用するマップオブジェクト
The map object to use
Returns
$this
setTypeMap() public ¶
setTypeMap(mixed $typeMap)
$typeMapが配列の場合は新しいTypeMapを作成し、それ以外の場合は指定された配列と交換します。
Creates a new TypeMap if $typeMap is an array, otherwise exchanges it for the given one.
Parameters
-
array|\Cake\Database\TypeMap
$typeMap -
配列の場合はTypeMapを作成し、それ以外の場合は指定されたTypeMapを設定します
Creates a TypeMap if array, otherwise sets the given TypeMap
Returns
$this
setValueBinder() public ¶
setValueBinder(?\Cake\Database\ValueBinder $binder)
現在の値バインダーを上書き
Overwrite the current value binder
ValueBinderは、クエリのプレースホルダーを生成し、それらのプレースホルダーに一時的に値を関連付けて、ステートメントオブジェクトに正しく渡せるようにします。
A ValueBinder is responsible for generating query placeholders and temporarily associate values to those placeholders so that they can be passed correctly to the statement object.
Parameters
-
\Cake\Database\ValueBinder|null
$binder -
バインダー、またはバインドを無効にするnull。
The binder or null to disable binding.
Returns
$this
shuffle() public ¶
shuffle()
インメモリは結果が返される順序をランダム化します
In-memory randomize the order the results are returned
skip() public ¶
skip(int $howMany)
クエリ結果の先頭から一部の行をスキップします。
Skips some rows from the start of the query result.
Parameters
-
int
$howMany
some() public ¶
some(callable $c)
結果の少なくとも1つが呼び出し可能テストに合格した場合にtrueを返します
Returns true if at least one of the results pass the callable test
Parameters
-
callable
$c
sortBy() public ¶
sortBy(mixed $callback, int $dir, int $type)
コールバックでクエリを並べ替えます
Sorts the query with the callback
Parameters
-
mixed
$callback -
int
$dir -
int
$type
sql() public ¶
sql(?\Cake\Database\ValueBinder $generator)
このオブジェクトのSQL表現を返します。
Returns the SQL representation of this object.
この関数は、このクエリをコンパイルして、接続で使用されるSQL方言と互換性を持たせます。このプロセスでは、クエリパーツまたは内部式を追加、削除、または変更して、ターゲットプラットフォームで実行可能にすることができます。
This function will compile this query to make it compatible with the SQL dialect that is used by the connection, This process might add, remove or alter any query part or internal expression to make it executable in the target platform.
結果のクエリには、クエリの実行時に実際の値に置き換えられるプレースホルダーが含まれる場合があるため、準備済みステートメントでの使用が最も適しています。
The resulting query may have placeholders that will be replaced with the actual values when the query is executed, hence it is most suitable to use with prepared statements.
Parameters
-
\Cake\Database\ValueBinder|null
$generator optional -
式に関連付けられた値を保持するプレースホルダーオブジェクト
A placeholder object that will hold associated values for expressions
Returns
string
stopWhen() public ¶
stopWhen(callable $c)
callableがtrueを返すまで、各行を返します。
Returns each row until the callable returns true.
Parameters
-
callable
$c
sumOf() public ¶
sumOf(string|callable $field)
単一の列のすべての値の合計を返します
Returns the sum of all values for a single column
Parameters
-
string|callable
$field
take() public ¶
take(int $size = 1, int $from = 0)
クエリ結果のメモリ内の制限とオフセット。
In-memory limit and offset for the query results.
Parameters
-
int
$size = 1 -
int
$from = 0
toArray() public ¶
toArray()
このクエリの結果を含むキーと値の配列を返します。
Returns a key-value array with the results of this query.
toList() public ¶
toList()
このクエリの結果を数値でインデックス付けされた配列で返します。
Returns a numerically indexed array with the results of this query.
traverse() public ¶
traverse(mixed $visitor)
指定されたすべての部分を反復します。 トラバース関数は、クロージャー内の変数またはインスタンス変数を使用して結果を集約できます。 この関数は、クエリの作成に使用されるすべてのクエリパーツをトラバースする方法として一般的に使用されます。
Will iterate over every specified part. Traversing functions can aggregate results using variables in the closure or instance variables. This function is commonly used as a way for traversing all query parts that are going to be used for constructing a query.
コールバックは2つのパラメーターを受け取ります。最初のパラメーターは反復されているクエリパーツの値で、2番目はそのようなパーツの名前です。
The callback will receive 2 parameters, the first one is the value of the query part that is being iterated and the second the name of such part.
Example
$query->select(['title'])->from('articles')->traverse(function ($value, $clause) {
if ($clause === 'select') {
var_dump($value);
}
});
Parameters
-
callable
$visitor -
各パーツに対して実行される関数または呼び出し可能
A function or callable to be executed for each part
Returns
$this
traverseExpressions() public ¶
traverseExpressions(callable $callback)
この関数はtraverse()関数と同様に機能しますが、式ツリー全体の完全な深さ走査を行う点が異なります。 これにより、このクエリ内に格納されている各ExpressionInterfaceオブジェクトに提供されているコールバック関数が、クエリの任意の部分のネストの深さで実行されます。
This function works similar to the traverse() function, with the difference that it does a full depth traversal of the entire expression tree. This will execute the provided callback function for each ExpressionInterface object that is stored inside this query at any nesting depth in any part of the query.
コールバックは、現在アクセスされている式を最初のパラメーターとして受け取ります。
Callback will receive as first parameter the currently visited expression.
Parameters
-
callable
$callback -
このクエリ内で見つかった各ExpressionInterfaceに対して実行される関数。
the function to be executed for each ExpressionInterface found inside this query.
Returns
$this
traverseParts() public ¶
traverseParts(callable $visitor, array $parts)
提供された部分を反復します。
Will iterate over the provided parts.
トラバース関数は、クロージャー内の変数またはインスタンス変数を使用して結果を集約できます。 このメソッドは、SQLクエリをレンダリングするために、クエリパーツのサブセットをトラバースするために使用できます。
Traversing functions can aggregate results using variables in the closure or instance variables. This method can be used to traverse a subset of query parts in order to render a SQL query.
コールバックは2つのパラメーターを受け取ります。最初のパラメーターは反復されているクエリパーツの値で、2番目はそのようなパーツの名前です。
The callback will receive 2 parameters, the first one is the value of the query part that is being iterated and the second the name of such part.
Example
$query->select(['title'])->from('articles')->traverse(function ($value, $clause) {
if ($clause === 'select') {
var_dump($value);
}
}, ['select', 'from']);
Parameters
-
callable
$visitor -
各パーツに対して実行される関数または呼び出し可能
A function or callable to be executed for each part
-
string[]
$parts -
トラバースするクエリパーツのリスト
The list of query parts to traverse
Returns
$this
triggerBeforeFind() public ¶
triggerBeforeFind()
クエリのリポジトリオブジェクトでbeforeFindイベントをトリガーします。
Trigger the beforeFind event on the query's repository object.
複数回トリガーされることはなく、選択したクエリに対してのみ。
Will not trigger more than once, and only for select queries.
type() public ¶
type()
このクエリのタイプを返します(選択、挿入、更新、削除)
Returns the type of this query (select, insert, update, delete)
Returns
string
union() public ¶
union(mixed $query, mixed $overwrite)
このクエリでUNION演算子と組み合わせて使用する完全なクエリを追加します。 これは、このクエリの結果セットと、渡されたクエリによって返される結果セットを組み合わせるために使用されます。 異なるクエリでこのメソッドを複数回呼び出すことにより、必要な数のクエリを追加できます。
Adds a complete query to be used in conjunction with an UNION operator with this query. This is used to combine the result set of this query with the one that will be returned by the passed query. You can add as many queries as you required by calling multiple times this method with different queries.
デフォルトでは、UNION演算子は重複する行を削除します。すべてのクエリにすべての行を含める場合は、unionAll()を使用します。
By default, the UNION operator will remove duplicate rows, if you wish to include every row for all queries, use unionAll().
Examples
$union = (new Query($conn))->select(['id', 'title'])->from(['a' => 'articles']);
$query->select(['id', 'name'])->from(['d' => 'things'])->union($union);
生成されます:
Will produce:
SELECT id, name FROM things d UNION SELECT id, title FROM articles a
Parameters
-
string|\Cake\Database\Query
$query -
UNION演算子で使用される完全なSQLクエリ
full SQL query to be used in UNION operator
-
bool
$overwrite optional -
操作するクエリのリストをリセットするかどうか
whether to reset the list of queries to be operated or not
Returns
$this
unionAll() public ¶
unionAll(mixed $query, mixed $overwrite)
このクエリでUNION ALL演算子と組み合わせて使用する完全なクエリを追加します。 これは、このクエリの結果セットと、渡されたクエリによって返される結果セットを組み合わせるために使用されます。 異なるクエリでこのメソッドを複数回呼び出すことにより、必要な数のクエリを追加できます。
Adds a complete query to be used in conjunction with the UNION ALL operator with this query. This is used to combine the result set of this query with the one that will be returned by the passed query. You can add as many queries as you required by calling multiple times this method with different queries.
UNIONとは異なり、UNION ALLは重複行を削除しません。
Unlike UNION, UNION ALL will not remove duplicate rows.
$union = (new Query($conn))->select(['id', 'title'])->from(['a' => 'articles']);
$query->select(['id', 'name'])->from(['d' => 'things'])->unionAll($union);
生成されます:
Will produce:
SELECT id, name FROM things d UNION ALL SELECT id, title FROM articles a
Parameters
-
string|\Cake\Database\Query
$query -
UNION演算子で使用される完全なSQLクエリ
full SQL query to be used in UNION operator
-
bool
$overwrite optional -
操作するクエリのリストをリセットするかどうか
whether to reset the list of queries to be operated or not
Returns
$this
update() public ¶
update(mixed $table)
更新クエリを作成します。
Create an update query.
これにより、クエリタイプが「更新」に変更されます。 set()およびwhere()メソッドと組み合わせて、更新クエリを作成できます。
This changes the query type to be 'update'. Can be combined with set() and where() methods to create update queries.
Parameters
-
string|\Cake\Database\ExpressionInterface|null
$table optional -
未使用のパラメータ。
Unused parameter.
Returns
$this
values() public ¶
values(mixed $data)
挿入クエリの値を設定します。
Set the values for an insert query.
複数の挿入は、values()を複数回呼び出すか、値セットの配列を提供することで実行できます。 さらに、$dataは、別のSELECTステートメントからデータを挿入するQueryインスタンスにすることもできます。
Multi inserts can be performed by calling values() more than one time, or by providing an array of value sets. Additionally $data can be a Query instance to insert data from another SELECT statement.
Parameters
-
array|\Cake\Database\Query|\Cake\Database\Expression\ValuesExpression
$data -
挿入するデータ。
The data to insert.
Returns
$this
Throws
Cake\Database\Exception
列を宣言する前に値を設定しようとした場合。 または、非挿入クエリに値を設定しようとした場合。
if you try to set values before declaring columns. Or if you try to set values on non-insert queries.
where() public ¶
where(mixed $conditions, array $types, bool $overwrite)
このクエリのWHERE句で使用される条件または条件セットを追加します。 条件は、比較演算子を含むキーとしてフィールドの配列として表現できます。配列の値は、フィールドをそのようなリテラルと比較するために使用されます。 最後に、条件は単一の文字列または文字列の配列として表すことができます。
Adds a condition or set of conditions to be used in the WHERE clause for this query. Conditions can be expressed as an array of fields as keys with comparison operators in it, the values for the array will be used for comparing the field to such literal. Finally, conditions can be expressed as a single string or an array of strings.
配列を使用する場合、各エントリはAND演算子を使用して残りの条件に結合されます。 この関数を連続して呼び出すと、AND演算子を使用して指定された新しい条件も結合されます。 さらに、他のクエリオブジェクトを含めることができる式オブジェクトを使用して値を表すことができます。
When using arrays, each entry will be joined to the rest of the conditions using an AND operator. Consecutive calls to this function will also join the new conditions specified using the AND operator. Additionally, values can be expressed using expression objects which can include other query objects.
このメソッドで作成された条件はすべて、SELECT、UPDATE、およびDELETEタイプのクエリで使用できます。
Any conditions created with this methods can be used with any SELECT, UPDATE and DELETE type of queries.
演算子を使用した条件:
Conditions using operators:
$query->where([
'posted >=' => new DateTime('3 days ago'),
'title LIKE' => 'Hello W%',
'author_id' => 1,
], ['posted' => 'datetime']);
前の例では、以下が生成されます:
The previous example produces:
WHERE posted >= 2012-01-27 AND title LIKE 'Hello W%' AND author_id = 1
2番目のパラメーターは、渡されるキーごとに予期されるタイプを指定するために使用されます。 有効なタイプは、マップされたDatabase\Typeクラスから使用できます。
Second parameter is used to specify what type is expected for each passed key. Valid types can be used from the mapped with Database\Type class.
論理積を使用したネスト条件:
Nesting conditions with conjunctions:
$query->where([
'author_id !=' => 1,
'OR' => ['published' => true, 'posted <' => new DateTime('now')],
'NOT' => ['title' => 'Hello']
], ['published' => boolean, 'posted' => 'datetime']
前の例では、以下が生成されます。
The previous example produces:
WHERE author_id = 1 AND (published = 1 OR posted < '2012-02-01') AND NOT (title = 'Hello')
論理積を使用して、好きなだけ条件をネストできます。 同じキーに対して2つの異なるオプションを定義したい場合があります。その場合は、各配列を新しい配列内にラップできます。
You can nest conditions using conjunctions as much as you like. Sometimes, you may want to define 2 different options for the same key, in that case, you can wrap each condition inside a new array:
$query->where(['OR' => [['published' => false], ['published' => true]])
3番目のパラメーターをfalse(デフォルト)に設定してwhere()を呼び出すたびに、AND演算子を使用して、渡された条件が前の保存済みリストに結合されることに注意してください。 また、このメソッドの連続した呼び出しで同じ配列キーを2回使用しても、以前の値はオーバーライドされません。
Keep in mind that every time you call where() with the third param set to false (default), it will join the passed conditions to the previous stored list using the AND operator. Also, using the same array key twice in consecutive calls to this method will not override the previous value.
式オブジェクトの使用:
Using expressions objects:
$exp = $query->newExpr()->add(['id !=' => 100, 'author_id' != 1])->tieWith('OR');
$query->where(['published' => true], ['published' => 'boolean'])->where($exp);
前の例では、以下が生成されます:
The previous example produces:
WHERE (id != 100 OR author_id != 1) AND published = 1
任意のフィールドの条件として使用されるその他のクエリオブジェクト。
Other Query objects that be used as conditions for any field.
複数のステップで条件を追加する:
Adding conditions in multiple steps:
呼び出し可能な関数を使用して複雑な式を作成できます。関数は、最初の引数として新しいQueryExpressionオブジェクトを受け取り、このクエリインスタンスを2番目の引数として受け取ります。 関数は、AND演算子を使用してクエリの条件のリストに追加される式オブジェクトを返す必要があります。
You can use callable functions to construct complex expressions, functions receive as first argument a new QueryExpression object and this query instance as second argument. Functions must return an expression object, that will be added the list of conditions for the query using the AND operator.
$query
->where(['title !=' => 'Hello World'])
->where(function ($exp, $query) {
$or = $exp->or(['id' => 1]);
$and = $exp->and(['id >' => 2, 'id <' => 10]);
return $or->add($and);
});
-
前の例では、以下が生成されます:
The previous example produces:
WHERE title != 'Hello World' AND (id = 1 OR (id > 2 AND id < 10))
文字列としての条件:
Conditions as strings:
$query->where(['articles.author_id = authors.id', 'modified IS NULL']);
前の例では、以下が生成されます:
The previous example produces:
WHERE articles.author_id = authors.id AND modified IS NULL
配列表記または式オブジェクトを使用すると、すべての値が正しく引用符で囲まれ、対応するデータベースのデータ型に自動的に変換されるため、SQLインジェクションからアプリケーションを保護できます。 文字列条件を使用する場合は、値が正しく引用符で囲まれていることを確認してください。 最も安全な方法は、文字列条件を使用しないことです。
Please note that when using the array notation or the expression objects, all values will be correctly quoted and transformed to the correspondent database data type automatically for you, thus securing your application from SQL injections. If you use string conditions make sure that your values are correctly quoted. The safest thing you can do is to never use string conditions.
Parameters
-
string|array|\Closure|null
$conditions optional -
フィルタリングする条件。
The conditions to filter on.
-
array
$types optional -
クエリに値をバインドするために使用されるタイプ名の連想配列
associative array of type names used to bind values to query
-
bool
$overwrite optional -
渡されたリストで条件をリセットするかどうか
whether to reset conditions with passed list or not
Returns
$this
whereInList() public ¶
whereInList(string $field, array $values, array $options)
このクエリのWHERE句で使用されるIN条件または条件セットを追加します。
Adds an IN condition or set of conditions to be used in the WHERE clause for this query.
このメソッドは、 'allowEmpty'をtrueに設定した場合、where()とは対照的に空の入力を許可します。 適切な健全性チェックなしで使用する場合は注意してください。
This method does allow empty inputs in contrast to where() if you set 'allowEmpty' to true. Be careful about using it without proper sanity checks.
Options:
-
types
- クエリに値をバインドするために使用されるタイプ名の連想配列types
- Associative array of type names used to bind values to query -
allowEmpty
- 空の配列を許可します。allowEmpty
- Allow empty array.
Parameters
-
string
$field -
フィールド
Field
-
array
$values -
値の配列
Array of values
-
array
$options optional -
オプション
Options
Returns
$this
whereNotInList() public ¶
whereNotInList(string $field, array $values, array $options)
このクエリのWHERE句で使用されるNOT IN条件または条件セットを追加します。
Adds a NOT IN condition or set of conditions to be used in the WHERE clause for this query.
このメソッドは、 'allowEmpty'をtrueに設定した場合、where()とは対照的に空の入力を許可します。 適切な健全性チェックなしで使用する場合は注意してください。
This method does allow empty inputs in contrast to where() if you set 'allowEmpty' to true. Be careful about using it without proper sanity checks.
Parameters
-
string
$field -
フィールド
Field
-
array
$values -
値の配列
Array of values
-
array
$options optional -
オプション
Options
Returns
$this
whereNotNull() public ¶
whereNotNull(mixed $fields)
クエリにNOT NULL条件を追加する簡易メソッド
Convenience method that adds a NOT NULL condition to the query
Parameters
-
array|string|\Cake\Database\ExpressionInterface
$fields -
nullであってはならない単一のフィールド、式、またはそれらのリスト。
A single field or expressions or a list of them that should be not null.
Returns
$this
whereNull() public ¶
whereNull(mixed $fields)
クエリにIS NULL条件を追加する簡易メソッド
Convenience method that adds a IS NULL condition to the query
Parameters
-
array|string|\Cake\Database\ExpressionInterface
$fields -
nullにする必要がある単一のフィールド、式、またはそれらのリスト。
A single field or expressions or a list of them that should be null.
Returns
$this
zip() public ¶
zip(array|\Traversable $c)
クエリと$cの両方の最初の結果を配列で返し、次に2番目の結果を返します。
Returns the first result of both the query and $c in an array, then the second results and so on.
Parameters
-
array|\Traversable
$c
zipWith() public ¶
zipWith(mixed $collections, callable $callable)
クエリの最初の行と各項目を使用して$cを呼び出した結果のそれぞれを返し、次に2番目の行を返します。
Returns each of the results out of calling $c with the first rows of the query and each of the items, then the second rows and so on.
Parameters
-
mixed
$collections -
callable
$callable
プロパティの詳細
Property Detail
$_autoFields ¶ protected
元のクエリに最上位のテーブルのフィールドを含めるかどうかを追跡します。
Tracks whether or not the original query should include fields from the top level table.
Type
bool|null
$_beforeFindFired ¶ protected
このクエリに対してbeforeFindイベントがすでにトリガーされている場合はtrue
True if the beforeFind event has already been triggered for this query
Type
bool
$_cache ¶ protected
このクエリでキャッシュが有効になっている場合のクエリキャッシュインスタンス。
A query cacher instance if this query has caching enabled.
Type
\Cake\Datasource\QueryCacher|null
$_connection ¶ protected
このクエリの実行に使用される接続インスタンス。
Connection instance to be used to execute this query.
Type
\Cake\Database\Connection
$_counter ¶ protected
limit
を使用しない場合にこのクエリが一致するレコードの合計量を計算するために使用できる呼び出し可能な関数
A callable function that can be used to calculate the total amount of records this query will match when not using limit
Type
callable|null
$_deleteParts ¶ protected
DELETEステートメントを生成するために全探索するクエリ句のリスト
The list of query clauses to traverse for generating a DELETE statement
Type
string[]
$_dirty ¶ protected
このクエリの内部状態が変更されたかどうかを示します。これは、変換されたクエリや実行されたステートメントへの参照など、内部にキャッシュされたオブジェクトを破棄するために使用されます。
Indicates whether internal state of this query was changed, this is used to discard internal cached objects such as the transformed query or the reference to the executed statement.
Type
bool
$_eagerLoaded ¶ protected
クエリがスタンドアロンであるか、熱心なロード操作の結果であるか。
Whether the query is standalone or the product of an eager load operation.
Type
bool
$_eagerLoader ¶ protected
関連付けの包含を格納し、このクエリが実行されたときにそれらを積極的にロードするクラスのインスタンス
Instance of a class responsible for storing association containments and for eager loading them when this query is executed
Type
\Cake\ORM\EagerLoader|null
$_formatters ¶ protected
フェッチ時に結果を後処理するフォーマッタクラスまたはコールバックのリスト
List of formatter classes or callbacks that will post-process the results when fetched
Type
callable[]
$_functionsBuilder ¶ protected
任意のSQL関数を生成するために使用される関数ビルダーオブジェクトのインスタンス。
Instance of functions builder object used for generating arbitrary SQL functions.
Type
\Cake\Database\FunctionsBuilder|null
$_hasFields ¶ protected
ユーザーが実行前にフィールドを選択するかどうかにかかわらず、これを使用して、フィールドを自動的に選択するかどうかを決定します。
Whether the user select any fields before being executed, this is used to determined if any fields should be automatically be selected.
Type
bool|null
$_hydrate ¶ protected
結果をエンティティオブジェクトにハイドレートするかどうか
Whether to hydrate results into entity objects
Type
bool
$_insertParts ¶ protected
INSERTステートメントを生成するために全探索するクエリ句のリスト
The list of query clauses to traverse for generating an INSERT statement
Type
string[]
$_iterator ¶ protected
このクエリの実行結果のステートメントオブジェクト。
Statement object resulting from executing this query.
Type
\Cake\Database\StatementInterface|null
$_mapReduce ¶ protected
クエリ結果に適用する必要のあるmap-reduceルーチンのリスト
List of map-reduce routines that should be applied over the query result
Type
array
$_options ¶ protected
このクラスのメソッドで処理できなかった、applyOptionsを使用して渡されたカスタムオプションを保持します。
Holds any custom options passed using applyOptions that could not be processed by any method in this class.
Type
array
$_parts ¶ protected
このクエリの作成に使用されるSQLパーツのリスト。
List of SQL parts that will be used to build this query.
Type
array
$_repository ¶ public
このクエリがバインドされているテーブルオブジェクトのインスタンス。
Instance of a table object this query is bound to.
Type
\Cake\ORM\Table
$_resultDecorators ¶ protected
取得時に結果のステートメントから各行を変更するために呼び出されるコールバック関数のリスト。 コールバック関数はそれぞれ、最初の引数として行配列を受け取ります。
A list of callback functions to be called to alter each row from resulting statement upon retrieval. Each one of the callback function will receive the row array as first argument.
Type
callable[]
$_results ¶ protected
ResultSet。
A ResultSet.
設定すると、クエリの実行がバイパスされます。
When set, query execution will be bypassed.
Type
iterable|null
$_resultsCount ¶ protected
クエリのCOUNT(*)。
The COUNT(*) for the query.
設定すると、カウントクエリの実行がバイパスされます。
When set, count query execution will be bypassed.
Type
int|null
$_selectParts ¶ protected
SELECTステートメントを生成するために全探索するクエリ句のリスト
The list of query clauses to traverse for generating a SELECT statement
Type
string[]
$_selectTypeMap ¶ protected
select句のフィールドのタイプマップ
The Type map for fields in the select clause
Type
\Cake\Database\TypeMap
$_type ¶ protected
このクエリのタイプ(選択、挿入、更新、削除)。
Type of this query (select, insert, update, delete).
Type
string
$_updateParts ¶ protected
UPDATEステートメントを生成するために全探索するクエリ句のリスト
The list of query clauses to traverse for generating an UPDATE statement
Type
string[]
$_useBufferedResults ¶ protected
バッファリングされた結果が有効かどうかを追跡するためのブール値。
Boolean for tracking whether or not buffered results are enabled.
Type
bool
$_valueBinder ¶ protected
クエリプレースホルダーを生成し、それぞれに関連付けられた値を一時的に格納するオブジェクト。
The object responsible for generating query placeholders and temporarily store values associated to each of those.
Type
\Cake\Database\ValueBinder|null