many-to-many

Symfony2-Doctrine: ManyToMany relation is not saved to database

梦想与她 提交于 2019-11-26 04:41:13
问题 I have two PHP model classes named Category and Item. A Category may have many Items and an Item may belong to many Categories. I have created a ManyToMany relation to both classes: class Category { /** * @ORM\\ManyToMany(targetEntity=\"Item\", mappedBy=\"categories\", cascade={\"persist\"}) */ private $items; /** * Add items * * @param Ako\\StoreBundle\\Entity\\Item $items */ public function addItems(\\Ako\\StoreBundle\\Entity\\Item $items) { $this->items[] = $items; } /** * Get items * *

Many-to-many mapping table

浪尽此生 提交于 2019-11-26 04:19:16
问题 From examples that I have seen online and in a Programming Entity Framework CodeFirst book, when you have a collection on both classes EF would create a mapping table such as MembersRecipes and the primary key from each class would link to this table. However when I do the below, I instead get a new field in the Recipes table called Member_Id and a Recipe_Id in the Members table. Which only creates two one-to-many relationships, but not a many-to-many so I could have Member 3 linked to

What is the difference between fetch=“EAGER” and fetch=“LAZY” in doctrine

不羁岁月 提交于 2019-11-26 03:58:29
问题 What is the difference between fetch=\"EAGER\" and fetch=\"LAZY\" in annotation @ManyToOne in Doctrine ? /** * @ManyToOne(targetEntity=\"Cart\", cascade={\"all\"}, fetch=\"EAGER\") */ /** * @ManyToOne(targetEntity=\"Cart\", cascade={\"all\"}, fetch=\"LAZY\") */ 回答1: To explain it simply, when you are loading an entity and if it has an association with one or more entities, what should doctrine do? If the association is marked as EAGER , it will fetch and load the associated entity as well. If

How to create a many-to-many mapping in Entity Framework?

风流意气都作罢 提交于 2019-11-26 03:07:33
问题 Here is the case, I have 2 entities, such as Contract、Media。 public class Media : Entity { public string Name {get; set;} public bool Enabled *//other properties can be ignored..* } public class Contract : Entity { public string Code {get; set;} *//other properties can be ignored..* } Contract has many Medias, it seems that they are many to many. But!! at ef code first, i need 3 more fields in the ContractMedia table(ef auto generated). such as StartDate,EndDate and Price. these could not be

Mapping many-to-many association table with extra column(s)

心已入冬 提交于 2019-11-26 00:45:35
问题 My database contains 3 tables: User and Service entities have many-to-many relationship and are joined with the SERVICE_USER table as follows: USERS - SERVICE_USER - SERVICES SERVICE_USER table contains additional BLOCKED column. What is the best way to perform such a mapping? These are my Entity classes @Entity @Table(name = \"USERS\") public class User implements java.io.Serializable { private String userid; private String email; @Id @Column(name = \"USERID\", unique = true, nullable =

What is `related_name` used for in Django?

两盒软妹~` 提交于 2019-11-26 00:26:45
问题 What is the related_name argument useful for on ManyToManyField and ForeignKey fields? For example, given the following code, what is the effect of related_name=\'maps\' ? class Map(db.Model): members = models.ManyToManyField(User, related_name=\'maps\', verbose_name=_(\'members\')) 回答1: The related_name attribute specifies the name of the reverse relation from the User model back to your model. If you don't specify a related_name , Django automatically creates one using the name of your

Create code first, many to many, with additional fields in association table

帅比萌擦擦* 提交于 2019-11-25 22:56:11
问题 I have this scenario: public class Member { public int MemberID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public virtual ICollection<Comment> Comments { get; set; } } public class Comment { public int CommentID { get; set; } public string Message { get; set; } public virtual ICollection<Member> Members { get; set; } } public class MemberComment { public int MemberID { get; set; } public int CommentID { get; set; } public int Something { get; set;

How to implement a many-to-many relationship in PostgreSQL?

谁说胖子不能爱 提交于 2019-11-25 22:27:47
问题 I believe the title is self-explanatory. How do you create the table structure in PostgreSQL to make a many-to-many relationship. My example: Product(name, price); Bill(name, date, Products); 回答1: The SQL DDL (data definition language) statements could look like this: CREATE TABLE product ( product_id serial PRIMARY KEY -- implicit primary key constraint , product text NOT NULL , price numeric NOT NULL DEFAULT 0 ); CREATE TABLE bill ( bill_id serial PRIMARY KEY , bill text NOT NULL , billdate

How do I access the child classes of an object in django without knowing the name of the child class?

喜欢而已 提交于 2019-11-25 20:43:32
In Django, when you have a parent class and multiple child classes that inherit from it you would normally access a child through parentclass.childclass1_set or parentclass.childclass2_set, but what if I don't know the name of the specific child class I want? Is there a way to get the related objects in the parent->child direction without knowing the child class name? Carl Meyer ( Update : For Django 1.2 and newer, which can follow select_related queries across reverse OneToOneField relations (and thus down inheritance hierarchies), there's a better technique available which doesn't require