Added category relationship

This commit is contained in:
snipe
2013-11-25 10:12:23 -05:00
parent 447a74928b
commit 5a2c6391bf
3 changed files with 13 additions and 14 deletions
@@ -38,8 +38,7 @@ class CategoriesController extends AdminController {
public function getCreate()
{
// Show the page
$category_options = array('0' => 'Top Level') + Category::lists('name', 'id');
return View::make('backend/categories/edit')->with('category_options',$category_options)->with('category',new Category);
return View::make('backend/categories/edit')->with('category',new Category);
}
@@ -63,7 +62,6 @@ class CategoriesController extends AdminController {
// Update the category data
$category->name = e(Input::get('name'));
$category->parent = e(Input::get('parent'));
$category->user_id = Sentry::getId();
// Was the asset created?
@@ -134,7 +132,6 @@ class CategoriesController extends AdminController {
// Update the category data
$category->name = e(Input::get('name'));
$category->parent = e(Input::get('parent'));
// Was the asset created?
if($category->save())
+6 -9
View File
@@ -12,20 +12,17 @@ class Category extends Elegant {
);
/**
* Get the parent category name
*/
public function parentname()
{
return $this->belongsTo('Category','parent');
}
public function has_models()
{
return $this->hasMany('Model', 'category_id')->count();
}
public function models()
{
return $this->hasMany('Model', 'category_id');
}
}
+6 -1
View File
@@ -10,7 +10,12 @@ class Model extends Elegant {
public function assets()
{
return $this->hasMany('Asset', 'model_id');
}
public function category()
{
return $this->belongsTo('Category', 'category_id');
}
}