1

I'm trying to implement Doctrine on top of legacy MySql database. For now it wokrs kind a great. But...

I have Events table whitch has following structure:

CREATE TABLE `events` (
  `uid` int(11) NOT NULL AUTO_INCREMENT,
  -- skipped ---
  `title` varchar(255) NOT NULL DEFAULT '',
  `category` text,
)...

And table Categories, whitch has categories. Structure is like...

CREATE TABLE `tx_tendsical_category` (
  ...
 `title` varchar(255) NOT NULL DEFAULT '',
  ...
)

Now... Category IDS are stored as comma (,) separated values in events.category field. How can i setup relations without much hassle... I need hasMany etc...

4

2 回答 2

3

如果您在使用数据库模式时遇到问题,请编写自己的 hydrator。当您获取所有数据时,解析它并返回正确的对象集合。

于 2010-12-01T11:44:51.607 回答
0

我是这样做的......也许有更好的方法?

public function getCategories(){
    return Doctrine_Query::create()
        ->from("Category c")
        ->where("c.uid IN ?",array(explode(",",$this->category)))
        ->execute(array(),Doctrine_Core::HYDRATE_ON_DEMAND);
}
于 2010-12-02T09:06:33.677 回答