Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Custom Column name #85

Closed
ahmad-mujamil opened this issue Aug 20, 2023 · 2 comments
Closed

Invalid Custom Column name #85

ahmad-mujamil opened this issue Aug 20, 2023 · 2 comments

Comments

@ahmad-mujamil
Copy link

ahmad-mujamil commented Aug 20, 2023

//User Model
public function kabupaten_kota() : BelongsToThrough
    {
        return $this->belongsToThrough(KabupatenKota::class,[Kecamatan::class,Kelurahan::class],null,'',
        [
            Kelurahan::class => "kelurahan_id",
            Kecamatan::class => "kecamatan_id",
        ]);

im getting error with wrong field name :
Column not found: 1054 Unknown column 'kecamatan.kabupaten_kotum_id' in 'on clause'

select `kabupaten_kota`.*, `kelurahan`.`id` as `laravel_through_key` from `kabupaten_kota` inner join `kecamatan` on `kecamatan`.`kabupaten_kotum_id` = `kabupaten_kota`.`id` inner join `kelurahan` on `kelurahan`.`kecamatan_id` = `kecamatan`.`id` where `kelurahan`.`id` in (413f8d14-3f09-11ee-9d07-274e137307ca)

how to change the kecamatan.kabupaten_kotum_id field with the right field name "kabupaten_kota_id" ?

@staudenmeir
Copy link
Owner

Hi @ahmad-mujamil,
Try this:

public function kabupaten_kota(): BelongsToThrough
{
    return $this->belongsToThrough(KabupatenKota::class,[Kecamatan::class,Kelurahan::class], null, '',
        [
            Kelurahan::class => "kelurahan_id",
            Kecamatan::class => "kecamatan_id",
            KabupatenKota::class => "kabupaten_kota_id",
        ]// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    );
}

@ahmad-mujamil
Copy link
Author

thanks a lot, now works perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants