Posts module, WHERE in content field
Created 6 years ago by gonziis

So I have a function where I find specific posts by their Title, the Title is translatable so I use whereHas to get to translations.

public function findManyByTranslation($text, $locale = "any") {
        return $this->model->live()->whereHas("translations", 
            function($query) use($text,$locale){    
                if($locale != "any"){
                    $query->where("title","like","%".$text."%")->where("locale",$locale);
                }else{
                    $query->where("title","like","%".$text."%");
                }
            }
        )->paginate(10);
    }

If I change title to content it shows an errors that the field is not found. I look into DB to see that the content field is somehow different, but cant really understand how exactly, probably because of WYSIWYG? Please help somebody

edster  —  6 years ago

Are you looking at the wrong table or?

gonziis  —  6 years ago

Maybe? Because it's in the PostRepository class ...

<?php namespace Anomaly\PostsModule\Post;

use Anomaly\PostsModule\Category\Contract\CategoryInterface;
use Anomaly\PostsModule\Post\Contract\PostInterface;
use Anomaly\PostsModule\Post\Contract\PostRepositoryInterface;
use Anomaly\PostsModule\Type\Contract\TypeInterface;
use Anomaly\Streams\Platform\Entry\EntryCollection;
use Anomaly\Streams\Platform\Entry\EntryRepository;

/**
 * Class PostRepository
 *
 * @link          http://pyrocms.com/
 * @author        PyroCMS, Inc. <support@pyrocms.com>
 * @author        Ryan Thompson <ryan@pyrocms.com>
 */
class PostRepository extends EntryRepository implements PostRepositoryInterface
{
...

Shouldnt it automatically get the right table? Because in the view, when I fetch the results I can do post.content but I can't access the content field in that function mentioned at my first post. That's the thing.

frednwt  —  6 years ago

Post, as Page, is typable, and the content is a Type custom field (translatable).

So for example the default content is in app_posts_default_posts_translations.

Basicaly each Post type will generate a new table in the database for it own type (well 2 with the translations). And all custom fields will be added there.

gonziis  —  6 years ago

I understand, but how through the model, like the function I showed above, I can get to the content field with where function? I can't really wrap my mind around that.

ryanthompson  —  6 years ago

Posts and pages use a "type" pattern so the content structure changes from page type to page type. It's probably best to use the search query on pages to leverage the search engine since it's got the compiled content already stored.