【发布时间】:2019-07-16 14:29:36
【问题描述】:
更新
我的方法是接收相当于 simpel mysql 连接的东西。我想要来自 table tx 的所有条目,其中 project_id = x 在 tx.id = txevent.tx_id 上加入了 txevent。
我正在使用流明 5.5
更新 2
以下原始 sql 将完全符合我的要求:
$rawTx = DB::>table('tx')
->join('txevent', 'txevent.tx_id', '=', 'tx.id')
->where('tx.project_id', $request->get('project_id'))
->where('txevent.short_id', $request->get('short_id'))
->get();
难道不能通过关系达到同样的效果吗?
结束更新
我有两张桌子tx 和txevent:
发送:
id, int, autoincrement
project_id, int
txevent:
id, int, autoincrement
tx_id, int, fk(tx.id)
shortnumber, char
在 tx.php 我有以下方法:
public function txeventWithShortnumber($shortnumber)
{
return $this->hasOne('App\Txevent')->where('shortnumber', $shortnumber)->first();
}
在 TxController.php 中我会这样做:
$tx = Tx::where('project_id', $request->get('project_id'))->txeventWithShortnumber($request->get('shortnumber'))->get();
因此我收到以下错误消息:
(1/1) 错误方法调用异常 调用未定义的方法 Illuminate\Database\Query\Builder::txeventWithShortnumber()
在 Builder.php 第 2483 行
谁能告诉我我做错了什么?
【问题讨论】:
-
可以有多个
txevent对一个tx不考虑短号码吗? -
是的,1 tx 可以有 n txevent