M
M
Mykola2015-06-06 00:02:52
PHP
Mykola, 2015-06-06 00:02:52

Why does the selection from 2 tables not work?

I'm sitting for an hour and I can't make a selection from 2 tables in any way.
There are two tables. anime_short and anime_long.
anime_short
7226602.pnganime_long Foreign
7219434.png
key defined for anime_long table:
ALTER TABLE `anime_long` ADD CONSTRAINT `anime_long_ibfk_1` FOREIGN KEY (`short_id`) REFERENCES `cakephp3_db`.`anime_short`(`id`) ON DELETE CASCADE ON UPDATE NO ACTION; anime_short
initialization function

public function initialize(array $config)
    {
        $this->table('anime_short');
        $this->hasOne('anime_long');
        $this->displayField('id');
        $this->primaryKey('id');
    }

anime_long initialization function
public function initialize(array $config)
    {
        $this->table('anime_long');
        $this->belongsTo('AnimeShort', [
            'foreignKey' => 'short_id',
            'joinType' => 'INNER'
        ]);
    }

I do the selection like this:
$this->loadModel('AnimeShort');
$a_s = $this->AnimeShort->get(108);
 debug($a_s);

Returns data from the first table.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2015-06-06
@AmberLEX

Maybe you need to add something like
See here book.cakephp.org/3.0/en/orm/associations.html#haso...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question