Pyro CMS Repository
Created 4 years ago by peterombaorepublisyscomrepository query with translations? example my title column is translatable and i like to put it in where query. this is my query return $this->model->where ('title', 'string')->get(); but there's an error that says unknown column 'title' because it is in the translatable table. help!
peterombaorepublisyscom
—
4 years ago
what about $query->where like $stream->getEntryTranslationsTableName()?
peterombaorepublisyscom
—
4 years ago
like this? public function findSearchItems(StreamInterface $stream){ return $this->model ->where($stream->getEntryTranslationsTableName() . '.local', 'en') ->orderBy('id', 'desc')->paginate(4); }
peterombaorepublisyscom
—
4 years ago
I don't know how to work it in the repository
ryanthompson
—
4 years ago
Try something like this:
public function findByTitle($title)
{
$query = $this->model->newQuery();
$stream = $this->model->getStream();
$query->leftJoin(
$stream->getEntryTranslationsTableName(),
$stream->getEntryTableName() . '.id',
'=',
$stream->getEntryTranslationsTableName() . '.entry_id'
);
// Then you could do something like this.
$query->where($stream->getEntryTranslationsTableName() . '.local', 'en');
// Don't forget to restrict by your title.
$query->where($stream->getEntryTranslationsTableName() . '.title', 'LIKE', '%' . $title . '%');
// Return the results.
return $query->get();
}
Ok - so doing this via API right now is a little manual but there are some methods you can use. Let's reference this file for example https://github.com/anomalylabs/streams-platform/blob/master/src/Addon/FieldType/FieldTypeQuery.php
In this case
$query
is your query builder and$stream
is aStreamInterface
.You can do this same thing within your repository as well! Hope this helps.