Doctrine - 字段中的逗号分隔值

发布于 2024-10-05 18:43:09 字数 541 浏览 0 评论 0原文

我正在尝试在旧版 MySql 数据库之上实现 Doctrine。现在它工作得很好。但是......

我有事件表,其具有以下结构:

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

和表类别,其中有类别。结构就像...

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

现在...类别 IDS 存储为逗号 (,) 分隔值在 events.category 字段中。我如何才能轻松设置关系...我需要 hasMany 等...

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我太投入 2024-10-12 18:43:09

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

If you are having problems with database schema, write your own hydrators. When you'll have all data fetched, parse it and return proper object collections.

手心的海 2024-10-12 18:43:09

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

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);
}

I did it this way... Perhapse there is better way?

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文