【问题标题】:Eloquent relation without model没有模型的雄辩关系
【发布时间】:2015-06-27 19:01:47
【问题描述】:

假设我们有两张桌子:

products                product_langs
==============          ==============
   id                      id_product
   name                    lang
                           description

现在我想将这两个表链接在一起,例如:

return $product->hasOne('App/ProductLang')
  ->where('id_product', '=', 'id')
  ->where('lang', '=', $lang);

在没有模型App/ProductLang 的情况下,是否有开箱即用的可能性?

【问题讨论】:

  • 使用查询生成器
  • 我从你的标题中删除了标签,为你的 php 代码添加了语法高亮,改进了格式和语法。

标签: php laravel eloquent relationship


【解决方案1】:

您在这里混淆了关系定义和构建查询。

如果您不想定义另一个模型,那么忘记 hasOne() 并使用带有联接的查询构建器,如此处所述 http://laravel.com/docs/5.0/queries#joins

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 2013-06-04
    • 2016-11-26
    • 2021-01-27
    • 2018-02-19
    • 2019-04-18
    相关资源
    最近更新 更多