Closed jechazelle closed 2 years ago
Do you have a block_type_id
/type_id
column in the blocks
table?
Yes, I have a block_type_id
column in the blocks
table, I updated my code.
With this relation :
public function blockType()
{
return $this->hasOneDeep(BlockType::class, ['sections_blocks_linker', Block::class, 'block_types']);
}
I have this error :
Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'block_types' (SQL: select `block_types`.*, `sections_blocks_linker`.`section_id` as `laravel_through_key` from `block_types` inner join `block_types` on `block_types`.`block_type_id` = `block_types`.`id` inner join `blocks` on `blocks`.`id` = `block_types`.`block_id` inner join `sections_blocks_linker` on `sections_blocks_linker`.`block_id` = `blocks`.`id` where `sections_blocks_linker`.`section_id` in (1))
Use this relationship:
public function blockType()
{
return $this->hasOneDeep(
BlockType::class,
['sections_blocks_linker', Section::class, 'sections_blocks_linker', Block::class],
[null, null, null, null, 'id'],
[null, null, null, null, 'block_type_id']
);
}
With this relationship (on section
model), I have this error :
Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'sections_blocks_linker' (SQL: select `block_types`.*, `sections_blocks_linker`.`section_id` as `laravel_through_key` from `block_types` inner join `blocks` on `blocks`.`block_type_id` = `block_types`.`id` inner join `sections_blocks_linker` on `sections_blocks_linker`.`block_id` = `blocks`.`id` inner join `sections` on `sections`.`id` = `sections_blocks_linker`.`section_id` inner join `sections_blocks_linker` on `sections_blocks_linker`.`section_id` = `sections`.`id` where `sections_blocks_linker`.`section_id` in (1))
public function blockType()
{
return $this->hasOneDeep(
BlockType::class,
['sections_blocks_linker', Block::class],
[null, null, 'id'],
[null, null, 'block_type_id']
);
}
Whouu, perfect : Thank you so much @staudenmeir !!
Hi ! 👋
I use your package eloquent-has-many-deep : thank you so much for your job : it’s really awesome ! 🚀
Currently I have a question about your package, I have this tables :
I use your package to get hasManyDeep
sections
-> hasMany ->blocks
-> hasMany ->fragments
with this on section model :It works !
But I would like to get the block type :
Container
-> HasMany ->Section
-> HasMany ->Block
-> BelongsTo ->BlockType
I added this in the section model :
But it doesn’t work, do you have an idea please ?
My eloquent request :
Thank you so much for your answer