Have you seen our video tutorials? Check 'em out!

Pyro CMS Repository

peterombaorepublisyscom - 3 months ago

repository 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!

ryanthompson - 3 months ago

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 a StreamInterface.

$query->leftJoin(
    $stream->getEntryTranslationsTableName(),
    $stream->getEntryTableName() . '.id',
    '=',
    $stream->getEntryTranslationsTableName() . '.entry_id'
);

// Then you could do something like this.
$query->where($stream->getEntryTranslationsTableName() . '.local', 'en');

You can do this same thing within your repository as well! Hope this helps.

peterombaorepublisyscom - 3 months ago

what about $query->where like $stream->getEntryTranslationsTableName()?

peterombaorepublisyscom - 3 months ago

like this? public function findSearchItems(StreamInterface $stream){ return $this->model ->where($stream->getEntryTranslationsTableName() . '.local', 'en') ->orderBy('id', 'desc')->paginate(4); }

peterombaorepublisyscom - 3 months ago

I don't know how to work it in the repository

ryanthompson - 3 months 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();
}