【发布时间】:2014-06-01 15:09:49
【问题描述】:
我有下表
Schema::create('jokes_categories', function(Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('is_active');
$table->timestamps();
});
Schema::create('jokes', function(Blueprint $table) {
$table->increments('id');
$table->string('content', 200)->unique();;
$table->enum('is_active', array('Y', 'N'));
$table->integer('category_id')->unsigned();
$table->foreign('category_id')->references('id')->on('jokes_categories');
$table->timestamps();
});
笑话表中category_id是外键,与jokes_categories是一对多关系
在模型中我有以下内容:
class Joke extends \Eloquent {
public static $rules = array();
// Don't forget to fill this array
protected $fillable = array();
public function JokesCategory(){
return $this->belongsTo('JokesCategory');
}
}
在控制器中我有以下内容:
$jokes = Joke::all();
但拉不通joke_categories.name(我的印象是模型定义会直接帮助拉取相关模型)
有什么解决办法?
【问题讨论】:
标签: php orm laravel laravel-4 eloquent