【发布时间】:2013-08-13 22:22:18
【问题描述】:
我有两个课程:学位和大学,
class Degree extends Eloquent {
public function title(){
return $this->degree_title;
}
public function college(){
return $this->belongsTo('College','college_code');
}
}
class College extends Eloquent {
public function title(){
return $this->college_title;
}
}
我将它设置为belongsTo,因为它在hasOne()上中断,错误是:
Call to a member function getResults() on a non-object
如果这是在正确的方向,我不确定。
我一直在尝试的是使用 slug 搜索学位(它有助于更好的分析),然后将结果传递给我创建的刀片。
注意:有一个 Degrees 表和一个 Colleges 表,我可以在没有连接的情况下运行查询:
学位控制器:
class DegreeController extends BaseController {
public function single($slug)
{
$degree = Degree::where('slug', '=', $slug)->get();
return View::make('degrees.single', array('degree' => $degree));
}
}
单一视图:
@extends('master')
{{ -- Single Degree Blade-- }}
@section('content')
@foreach($major as $m)
<div>
<h1>{{ $m->title() }}</p>
<p>{{ $m->college->title() }}</p>
<p>Holland: {{ $m->holland() }}</p>
</div>
@endforeach
@stop
我注意到的是使用$m->college->title() 会导致错误:
SQLSTATE [42S22]:找不到列:1054 'where 子句'中的未知列 'colleges.id'(SQL:select * from colleges where colleges.id = ?limit 1)(绑定:数组(0 => 'UAGSC', ))
这表明它忽略了我的自定义键,它不是 id 也不是整数,它是一个特定的 5 字母 varchar。
任何人都可以就如何处理这个问题给我任何建议吗?
【问题讨论】: