class Model_Adv extends ORM {
protected $_table_name = 'board_adv';
protected $_has_many = array(
'category' => array(
'model' => 'adv_category',
'through' => 'board_adv_categories',
'foreign_key' => 'adv_id',
'far_key' => 'category_id'
),
'image' => array(
'model' => 'adv_image',
'through' => 'board_adv_images',
'foreign_key' => 'adv_id',
'far_key' => 'images_id'
),
);
}
class Model_Adv_Category extends ORM {
protected $_table_name = 'board_categories';
protected $_has_many = array(
'adv' => array(
'model' => 'adv',
'through' => 'board_adv_categories',
'foreign_key' => 'category_id',
'far_key' => 'adv_id'
)
);
}
public function action_delete()
{
$id = $this->request->param('id');
$category = ORM::factory('adv_category',$id);
$adv=$category->adv->find_all();
foreach ($adv as $advs) {
$advs->delete();
}
$category_list = ORM::factory('adv_category')->where('category_id', '=', $id);
foreach ($category_list->find_all() as $categories) {
$categories->delete();
}
$category->delete();
Request::initial()->redirect('/board/');
}
CREATE TABLE IF NOT EXISTS `boards_adv_images` (
`adv_id` int(11) NOT NULL,
`images_id` int(11) NOT NULL,
KEY `adv_id` (`adv_id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251;
--
-- Dumping data for table `boards_adv_images`
--
-- --------------------------------------------------------
--
-- Table structure for table `board_adv`
--
CREATE TABLE IF NOT EXISTS `board_adv` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` char(128) NOT NULL,
`content` varchar(1024) NOT NULL,
`created` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=4 ;
--
-- Dumping data for table `board_adv`
--
-- --------------------------------------------------------
--
-- Table structure for table `board_adv_categories`
--
CREATE TABLE IF NOT EXISTS `board_adv_categories` (
`adv_id` int(11) NOT NULL,
`category_id` int(11) NOT NULL,
KEY `adv_id` (`adv_id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251;
--
-- Dumping data for table `board_adv_categories`
--
-- --------------------------------------------------------
--
-- Table structure for table `board_categories`
--
CREATE TABLE IF NOT EXISTS `board_categories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category_id` int(11) NOT NULL,
`title` char(128) NOT NULL,
`content` varchar(1024) NOT NULL,
`created` int(11) NOT NULL,
`adv_count` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=28 ;
--
-- Dumping data for table `board_categories`
--
INSERT INTO `board_categories` (`id`, `category_id`, `title`, `content`, `created`, `adv_count`) VALUES
(5, 0, 'Работа и бизнес', '', 1344756622, 0),
(6, 0, 'Для дома и дачи', '', 1344756633, 0),
(4, 0, 'Недвижимость', '', 1344756610, 0),
(7, 0, 'Хобби и отдых', '', 1344756646, 0),
(8, 0, 'Транспорт', '', 1344756659, 0),
(9, 0, 'Личные вещи', '', 1344756671, 0),
(10, 0, 'Бытовая электроника', '', 1344756685, 0),
(11, 0, 'Животные', '', 1344756699, 0),
(12, 4, 'Квартиры', '', 1344756762, 0),
(13, 4, 'Комнаты', '', 1344756776, 0),
(14, 4, 'Недвижимость за рубежом', '', 1344756799, 0),
(15, 4, 'Дома, дачи, коттеджи', '', 1344756813, 0),
(16, 4, 'Коммерческая недвижимость', '', 1344756838, 0),
(17, 4, 'Земельные участки', '', 1344756856, 0),
(18, 4, 'Гаражи и машиноместа', '', 1344756875, 0);
-- --------------------------------------------------------
--
-- Table structure for table `board_images`
--
CREATE TABLE IF NOT EXISTS `board_images` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`path` char(64) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=1 ;