- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
TwitterTweets 实体:
/**
* MyBundle\CoreBundle\Entity\TwitterTweets
*
* @ORM\Table(name="twitter_tweets")
* @ORM\Entity
*/
class TwitterTweets
{
/**
* @var TwitterUsers
*
* @ORM\ManyToOne(targetEntity="TwitterUsers", inversedBy="tweets")
* @ORM\JoinTable(name="twitter_tweets",
* joinColumns={
* @ORM\JoinColumn(name="twitter_user_id", referencedColumnName="twitter_id")
* }
* )
*/
private $twitterUser;
}
TwitterUsers 实体:
/**
* MyBundle\CoreBundle\Entity\TwitterUsers
*
* @ORM\Table(name="twitter_users")
* @ORM\Entity
*/
class TwitterUsers
{
/**
* @var TwitterTweets
*
* @ORM\OneToMany(targetEntity="TwitterTweets", mappedBy="twitterUser")
*/
private $tweets;
}
twitter_tweets 表:
CREATE TABLE `twitter_tweets` (
`period` int(6) unsigned NOT NULL,
`tweet_id` varchar(30) NOT NULL,
`twitter_user_id` bigint(20) unsigned NOT NULL,
`tweet` varchar(255) NOT NULL,
`url` text NOT NULL,
`retweet_count` varchar(10) NOT NULL DEFAULT '0',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`period`,`tweet_id`),
KEY `period` (`period`),
KEY `tweet_id` (`tweet_id`),
KEY `twitter_user_id` (`twitter_user_id`),
KEY `created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
twitter_users 表:
CREATE TABLE `twitter_users` (
`twitter_id` bigint(20) unsigned NOT NULL,
`user` varchar(255) NOT NULL,
`username` varchar(255) NOT NULL,
`profile_image_url` text NOT NULL,
PRIMARY KEY (`twitter_id`),
KEY `user` (`user`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我在执行简单的 SELECT 时遇到此错误:
$this->getDoctrine()->getRepository('MyBundleCoreBundle:TwitterTweets')->findOneBy(array( 'tweetId' => $data->tweet_id ))
未找到列:1054“字段列表”中的未知列“t0.twitterUser_id”
SELECT t0.period AS period1, t0.tweet_id AS tweet_id2, t0.tweet AS tweet3,
t0.url AS url4, t0.retweet_count AS retweet_count5, t0.created_at AS created_at6,
t0.twitterUser_id AS twitterUser_id7
FROM twitter_tweets t0 WHERE t0.tweet_id = ?
我该如何解决这个问题?我试图只设置 @ORM\JoinColumn (没有 JoinTable 注释)但我得到这个错误:
“消息”:“SQLSTATE[42S02]:未找到基表或 View :1146 表‘database.twittertweets_twittertrends’不存在”
最佳答案
使用多对一单向关联映射解决:http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/association-mapping.html#many-to-one-unidirectional
TwitterTweets 实体:
/**
* MyBundle\CoreBundle\Entity\TwitterTweets
*
* @ORM\Table(name="twitter_tweets")
* @ORM\Entity
*/
class TwitterTweets
{
/**
* @var TwitterUsers
*
* @ORM\ManyToOne(targetEntity="TwitterUsers")
* @ORM\JoinColumn(name="twitter_user_id", referencedColumnName="twitter_id")
*/
private $twitterUser;
}
TwitterUsers 实体:
/**
* MyBundle\CoreBundle\Entity\TwitterUsers
*
* @ORM\Table(name="twitter_users")
* @ORM\Entity
*/
class TwitterUsers
{
// ... no properties needed
}
感谢 jperovic 的帮助:)
关于php - Doctrine 2 ManyToOne 映射注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9739254/
我只是没有明白这一点。下面的代码是怎么回事,哪里出错了?我必须上课:资源和预订。一个资源可以有多个预留,并且关系是双向的。对我来说,一切似乎都找到了,我已经查看了一堆资源和文档 - 是的,还有很多示例
我正在寻找有关大型遗留模式映射的一些建议。 情况是这样的。假设我们有一个名为 BusinessTransaction 的类。此类有几个引用用户 ID 的字段: @Entity public class
我正在寻找有关大型遗留模式映射的一些建议。 情况是这样的。假设我们有一个名为 BusinessTransaction 的类。此类有几个引用用户 ID 的字段: @Entity public class
我上课了: @Entity @Table(name="users") public class User{ private Integer id; private String name; priva
我有一个实体类 付款 其中有实体类 付款方式 与 多对一 关系。 现在因为我的 PaymentMethod 是主表。 所以我想在不影响主表 PaymentMethod 的情况下保存付款。 但是每次我保
关系的 @OneToMany 端填充良好,但 @ManyToOne 端每次都会覆盖(仅最后一项保留) @Entity @Table(name="order") public c
下面的联接保留了与每个客户端相关的 TaxJurisdictions,但它不包括插入中联接 (CLIENT_CODE) 中使用的列,导致我的数据库表 TBL_TAX_JURISDICTION.CLIE
我得到了城市和天气。天气应该指向数据库中的城市对象。一个城市可以有多个天气条目。我的问题是,每次我向数据库添加天气时,它都会创建一个具有相同名称但具有其他 ID 的新城市。 天气实体; @Entity
所以我的数据库中有一份文档有修订。文档表包含文档通用的元数据,修订版包含内容。目前我可以获得正确修订的文档。 我想做的是通过映射的所有修订获取文档列表。 这是我的两个实体: @Entity publi
大家好。 我有一个问题让我睡不着)例如,如果我有一个名为 Product 的实体(类)。我应该将这个产品与一堆图像链接起来。在数据库(在我的例子中是MySQL)中,我会创建一个产品表和图像表。图像表将
我使用 Spring Roo 对 MySQL 数据库进行逆向工程,这是一个我只有读取权限的数据库。 其中一个名为 Transaction 的实体有一个名为 originalTransaction 的字
我可以建立如下关系吗: @Entity Table1{ @ManyToOne @JoinColumn(name = "Column1", referen
我有以下单向 ManyToOne 关系: @Entity @Table(name = "Child") public class Child { @Id private Integer
我的关系非常简单,我的模型如下所示: public class Project { [PrimaryKey, AutoIncrement] public int ID { get; s
我有以下数据库结构: CREATE TABLE `author` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255
目录 jpa实体@ManyToOne @OneToMany无限递归 问题描述 解决办法 @OneToMany和@ManyTo
我在保存具有 ManyToOne 双向关系的实体时遇到问题,这里是: 警告:HHH000437:正在尝试保存一个或多个与未保存的 transient 实体具有不可空关联的实体。在保存这些依赖实体之前,
我有 2 个实体 - 具有映射 @ManyToOne 的用户和角色。我想更改用户角色,但角色也想更新。 用户实体: @ManyToOne @JoinColumn(name = "role_id", i
我有 4 个类如下... @MappedSuperclass @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) public abstrac
想象一下下面的类 @Embeddable class A { @ManyToOne public B classB; ... public State someEnum
我是一名优秀的程序员,十分优秀!