【问题标题】:Column 'id' in field list is ambiguous using Eloquent使用 Eloquent,字段列表中的列 'id' 不明确
【发布时间】:2016-06-28 16:42:45
【问题描述】:

有谁知道为什么以下导致字段列表中的 Column 'id' is ambiguous 错误?

$app_subj_current = \DB::table('tbl_subject')
        ->join('tbl_application', 'tbl_subject.id', '=', 'tbl_application.app_subj_id')
        ->where('tbl_application.id', $application)
        ->lists('tbl_subject.subj_type', 'tbl_subject.id');

我已经指定了我所指的 ID 表,所以我不明白为什么会出现这个错误。

【问题讨论】:

    标签: php sql laravel eloquent


    【解决方案1】:

    使用select() 而不是lists()。希望它有效。

    【讨论】:

    • 这导致 htmlentities() 期望参数 1 为字符串,对象给定错误
    • 我出于好奇尝试过它,但它仍然导致 htmlentities() 期望参数 1 是字符串,对象给定错误。不过,我有一个可行的解决方法(请参阅我的答案)。
    【解决方案2】:

    我发现以下方法可以解决问题:

    $app_subj_current = \DB::table('tbl_subject')
        ->join('tbl_application', 'tbl_subject.id', '=', 'tbl_application.app_subj_id')
        ->where('tbl_application.id', $application)
        ->select('tbl_subject.subj_type as x', 'tbl_subject.id as y')
        ->lists('x', 'y');
    

    【讨论】:

      猜你喜欢
      • 2011-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-01
      • 2020-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多