Open thijsmans opened 7 years ago
Thank @thijsmans. I think you can use esIndex()
for your relationship.
Ex:
$book->esIndex();
$book->authors()->esIndex();
And you should be make sure your author
model already use ElasticModelTrait
.
Unfortunately that doesn't work:
$books = Book::all();
foreach( $books AS $book )
{
$book->authors()->esIndex();
}
results in
BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::esIndex()'
Ofcourse you could do a foreach-loop on $book->authors() and esIndex() all authors by themselves, but that would just index the author by itself and not in relation to the book...
Sorry @thijsmans. Please try: $book->authors->esIndex();
Because $book->authors
return a collection but $book->authors()
return a relationship object. And esIndex()
function only work with collection object :D
Thanks for a very nice simple and clean ES-client! Is there a way to index the relationships of my models, as if they were part of the model itself?
Example: model Book belongs to many Author's. Right now, the book is indexed but the author(s) is/are not. Authors could be indexed on their own, but not in relation to the books.