Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added id() and type() convenience methods on Elastic::Model::Role::Doc

which call the equivalent method on the doc's UID

Fixes #5
  • Loading branch information...
commit 1d460a0d4ae6e79f4b3303db224f9d0608f0a46f 1 parent e351eeb
@clintongormley authored
Showing with 22 additions and 0 deletions.
  1. +22 −0 lib/Elastic/Model/Role/Doc.pm
View
22 lib/Elastic/Model/Role/Doc.pm
@@ -20,6 +20,7 @@ has 'uid' => (
writer => '_set_uid',
traits => ['Elastic::Model::Trait::Exclude'],
exclude => 1,
+ handles => [ 'id', 'type' ]
);
#===================================
@@ -270,6 +271,27 @@ to you to ensure uniqueness. Either leave the ID blank, in which case
ElasticSearch will generate a unique ID, or ensure that the way you
generate IDs will not cause a collision.
+=head2 type / id
+
+ $type = $doc->type;
+ $id = $doc->id;
+
+C<type> and C<id> are provided as convenience, read-only accessors which
+call the equivalent accessor on L</uid>.
+
+You can defined your own C<id()> and C<type()> methods, in which case they
+won't be imported, or you can import them under a different name, eg:
+
+ package MyApp::User;
+ use Elastic::Doc;
+
+ with 'Elastic::Model::Role::Doc' => {
+ -alias => {
+ id => 'doc_id',
+ type => 'doc_type',
+ }
+ };
+
=head2 timestamp
$timestamp = $doc->timestamp($timestamp);
Please sign in to comment.
Something went wrong with that request. Please try again.