次のロックされたスキーマを含む Reads という名前のモデルがあるとします。
protected $_schema = array(
'_id' => array('type' => 'id'),
'name' => array('type' => 'string', 'unique' => true),
'read_by' => array('type' => 'string', 'array' => true)
);
「read_by」フィールドには、実際には特定の記事を読んだユーザーのリストが含まれています。モデルがロードされるか ::find() が呼び出されると、現在ログインしているユーザーの ID が read_by にある場合は true を返し、そうでない場合は false を返す「read」という別のフィールドが必要です。これは可能ですか?::applyFilter メソッドの使用を検討しましたが、そこからどこに行くべきかわかりません。
Mongo をデータベースとして使用しています。ありがとう。
以下のデイブの回答によると、 $chain->next($self, $params, $chain); によって設定された $result オブジェクトを編集します。フィルターでは、次のように表示されます。
lithium\data\collection\DocumentSet Object
(
[_original:protected] => Array
(
)
[_parent:protected] =>
[_pathKey:protected] =>
[_model:protected] => app\models\Reads
[_query:protected] => lithium\data\model\Query Object
(
[_map:protected] => Array
(
)
[_entity:protected] =>
[_data:protected] => Array
(
)
[_schema:protected] =>
[_classes:protected] => Array
(
[schema] => lithium\data\Schema
)
[_fields:protected] => Array
(
[0] => Array
(
)
[1] => Array
(
)
)
[_alias:protected] => Array
(
[Reads] => 1
)
[_paths:protected] => Array
(
[Reads] =>
)
[_models:protected] => Array
(
[Reads] => app\models\Reads
)
[_autoConfig:protected] => Array
(
[0] => map
)
[_initializers:protected] => Array
(
[0] => model
[1] => entity
[2] => conditions
[3] => having
[4] => group
[5] => order
[6] => limit
[7] => offset
[8] => page
[9] => data
[10] => calculate
[11] => schema
[12] => comment
)
[_built:protected] => 1
[_config:protected] => Array
(
[conditions] => Array
(
[feed_id] => Array
(
[$in] => Array
(
[0] => MongoId Object
(
[$id] => 51b79acbac53cfb51645ffa7
)
)
)
[read_by] => Array
(
[$nin] => Array
(
[0] => 51592dcc6d6d877c0a000002
)
)
)
[order] => Array
(
[date_added] => DESC
)
[limit] => 25
[user] => 51592dcc6d6d877c0a000002
[fields] =>
[page] =>
[with] => Array
(
)
[type] => read
[model] => app\models\Reads
[mode] =>
[source] => reads
[alias] => Reads
[having] => Array
(
)
[group] =>
[offset] =>
[joins] => Array
(
)
[data] => Array
(
)
[whitelist] => Array
(
)
[calculate] =>
[schema] =>
[comment] =>
[map] => Array
(
)
[relationships] => Array
(
)
)
[_methodFilters:protected] => Array
(
)
)
[_result:protected] => lithium\data\source\mongo_db\Result Object
(
[_cache:protected] =>
[_iterator:protected] => 0
[_current:protected] =>
[_started:protected] =>
[_init:protected] =>
[_valid:protected] =>
[_key:protected] =>
[_resource:protected] => MongoCursor Object
(
)
[_autoConfig:protected] => Array
(
[0] => resource
)
[_config:protected] => Array
(
[resource] => MongoCursor Object
(
)
[init] => 1
)
[_methodFilters:protected] => Array
(
)
)
[_valid:protected] => 1
[_stats:protected] => Array
(
)
[_started:protected] =>
[_exists:protected] =>
[_schema:protected] =>
[_autoConfig:protected] => Array
(
[0] => model
[1] => result
[2] => query
[3] => parent
[4] => stats
[5] => pathKey
[6] => exists
[7] => schema
)
[_data:protected] => Array
(
)
[_config:protected] => Array
(
[init] => 1
)
[_methodFilters:protected] => Array
(
)
)