Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
8792f21f
Commit
8792f21f
authored
Nov 25, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more docs
[ci skip]
parent
b081cf5e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
2 deletions
+37
-2
README.md
extensions/elasticsearch/README.md
+37
-2
No files found.
extensions/elasticsearch/README.md
View file @
8792f21f
...
...
@@ -67,10 +67,29 @@ The following is an example model called `Customer`:
```
php
class
Customer
extends
\yii\elasticsearch\ActiveRecord
{
/**
* @return array the list of attributes for this record
*/
public
function
attributes
()
{
return
[
'id'
,
'name'
,
'address'
,
'registration_date'
];
}
/**
* @return ActiveRelation defines a relation to the Order record (can be in other database, e.g. redis or sql)
*/
public
function
getOrders
()
{
return
$this
->
hasMany
(
Order
::
className
(),
[
'customer_id'
=>
'id'
])
->
orderBy
(
'id'
);
}
/**
* Defines a scope that modifies the `$query` to return only active(status = 1) customers
*/
public
static
function
active
(
$query
)
{
$query
->
andWhere
(
array
(
'status'
=>
1
));
}
}
```
...
...
@@ -89,4 +108,20 @@ It supports the same interface and features except the following limitations and
-
`via`
-relations can not be defined via a table as there are not tables in elasticsearch. You can only define relations via other records.
-
As elasticsearch is a data storage and search engine there is of course support added for search your records.
TBD ...
-
It is also possible to define relations from elasticsearch ActiveRecords to normal ActiveRecord classes and vice versa.
\ No newline at end of file
-
It is also possible to define relations from elasticsearch ActiveRecords to normal ActiveRecord classes and vice versa.
Elasticsearch separates primary key from attributes. You need to set the
`id`
property of the record to set its primary key.
Usage example:
```
php
$customer
=
new
Customer
();
$customer
->
id
=
1
;
$customer
->
attributes
=
[
'name'
=>
'test'
];
$customer
->
save
();
$customer
=
Customer
::
get
(
1
);
// get a record by pk
$customers
=
Customer
::
get
([
1
,
2
,
3
]);
// get a records multiple by pk
$customer
=
Customer
::
find
()
->
where
([
'name'
=>
'test'
])
->
one
();
// find by query
$customer
=
Customer
::
find
()
->
active
()
->
all
();
// find all by query (using the `active` scope)
```
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment