Welcome Guest, Not a member yet? Register   Sign In
How to select data from joined table
#1

Hi there,
I have a table and some relations in an 2nd one. My model for the first table works fine. But if I need data from this relation-table, it get Unknown column 'r.id' in 'field list'.
In detail, this is how my model is configured:
PHP Code:
    protected $table         'epoche';
    protected $primaryKey    'id';
    protected $returnType    'object';
    protected $allowedFields = ['id''slug''type''name']; 

and this is the method, I use
PHP Code:
    public function getRelationsTo($type$to$id NULL)
    {

        $query $this->builder()
            ->select('epoche.name, epoche.slug, r.id')
            ->where('epoche.type'$type);

        if ($to == 'below')
        {
            $query->join('epoche_relationship as r''r.epoche_id = epoche.id')
                ->where('r.type'$type)
                ->where('r.is_in_epoche_id'$id);
        
It works fine without the r.id in select. And as I understand, it is the model, which not allows the r.id-column from the 2nd table.

So, how to select data from joined tables if the model does not allow it?

Thanks

PS: I removed some data, so if there is missing something, this is not the reason of the error :-) My model works fine. But now, I need this ID and changed my model only on this little point.
Reply


Messages In This Thread
How to select data from joined table - by sprhld - 09-18-2021, 11:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB