many-to-many

EF 4.0 - Many to Many relationship - problem with deletes

断了今生、忘了曾经 提交于 2019-12-10 15:53:02
问题 My Entity Model is as follows: Person , Store and PersonStores Many-to-many child table to store PeronId,StoreId When I get a person as in the code below, and try to delete all the StoreLocations, it deletes them from PersonStores as mentioned but also deletes it from the Store Table which is undesirable. Also if I have another person who has the same store Id, then it fails saying "The DELETE statement conflicted with the REFERENCE constraint \"FK_PersonStores_StoreLocations\". The conflict

Many-to-many in sqlalchemy. Preventing SQLAlchemy from inserting into a table if a tag already exists

微笑、不失礼 提交于 2019-12-10 14:59:56
问题 I have a few ORM mapped tables, which (pared down) look like this: class Tag(Base): __tablename__ = 'tags' tag_name = Column(String, primary_key=True) task2tag_assoc = Table('tasktags', Base.metadata, Column('task_id', UUID, ForeignKey('tasks.task_id', ondelete='cascade'), primary_key=True), Column('tag_name', String, ForeignKey('tags.tag_name', ondelete='cascade'), primary_key=True) ) class Task(Base): __tablename__ = 'tasks' task_id = Column(UUID, primary_key=True) _tags = relationship('Tag

Doctrine 2.1 - Relation Lost After ManyToMany Cascade Merge - Symfony2

十年热恋 提交于 2019-12-10 14:47:47
问题 After merging an entity that has related entities with relations set to cascade both persist and merge operations the relations are lost! Here are the entities: class Event implements NormalizableInterface { /** * @ORM\ManyToMany(targetEntity="Participant", inversedBy="events", cascade={"persist", "merge"}) * @ORM\JoinTable(name="event_participant", * joinColumns={@ORM\JoinColumn(name="event_id", referencedColumnName="id", onDelete="CASCADE")}, * inverseJoinColumns={@ORM\JoinColumn(name=

JPA @ManyToMany Writing On Create But Not Update

六眼飞鱼酱① 提交于 2019-12-10 14:28:34
问题 My team has two classes, User and Store , related by JPA @ManyToMany annotations. The relevant code is below. When creating a new User object and setting its stores, life is good. But we're seeing some unexpected behavior when trying to update User objects through our Struts 2 / Spring web UI. (These problems do not occur when running simple automated integration tests through JUnit). Simply put, when saving a User , its stores collection is not updated -- the database shows no changes, and

Converting a many-to-many relationship to one-to-many in PostgreSQL

前提是你 提交于 2019-12-10 13:04:40
问题 I have a many-to-many between foo and bar modeled as a table foo_bar with foo_id and bar_id . I'd now like to model this as a one-to-many (which my data allows). I've added a foo_id column to bar but now I want to migrate my data. So, I want to UPDATE bar SET foo_id = f where id = b; where each f and b pair are coming from SELECT foo_id AS f, bar_id AS b FROM foo_bar; Is it possible to do this in SQL (and specifically PostgreSQL 9.0)? I know how to do sub-SELECTs in UPDATEs when there's only

Symfony - form - many to many relation - collection type

南楼画角 提交于 2019-12-10 12:15:51
问题 Here is the situation: I have an entity Property class Property { /** * @ORM\Id * @ORM\Column(type="string") * @ORM\GeneratedValue(strategy="UUID") */ protected $id; /** * @ORM\ManyToMany(targetEntity="PropertyEquipment", inversedBy="properties") */ protected $propertyEquipments; public function __construct() { $this->propertyEquipments = new ArrayCollection(); } public function getId() { return $this->id; } public function addPropertyEquipment(\AppBundle\Entity\PropertyEquipment

Propel: how to remove link made via many-to-many relation

谁说我不能喝 提交于 2019-12-10 12:13:19
问题 (link to previous question just in case: Struggling with one-to-many relation in an admin form) I have this many-to-many relation in my Symfony-1.3 / Propel-1.4 project between User and Partner . When the User is being saved, if it has certain boolean flag being true, I want to clear all the links to the partners. Here is what I do at the moment and it doesn't work: // inside the User model class public function save(PropelPDO $con = null) { if ($this->getIsBlaBla()) { $this-

Select a post that does not have a particular tag

倾然丶 夕夏残阳落幕 提交于 2019-12-10 11:57:11
问题 I have a post/tag database, with the usual post, tag, and tag_post tables. The tag_post table contains tagid and postid fields. I need to query posts. When I want to fetch posts that have a certain tag, I have to use a join: ... INNER JOIN tag_post ON post.id = tag_post.postid WHERE tag_post.tagid = {required_tagid}` When I want to fetch posts that have tagIdA and tagIdB, I have to use two joins (which I kind of came to terms with eventually). Now, I need to query posts that do not have a

How to setup custom join table in Entity Framework

北城余情 提交于 2019-12-10 11:49:44
问题 When setting up a many-to-many relationship with Code First approach, by default the join table only includes 2 columns (FK to PK of the 2 tables). 1) Is it possible/How can I setup a join table that will include some additional fields, and 2) how do I fill these values via code? For example: class Student { public int Id { get; set; } public string Name { get; set; } public List<Course> Courses { get; set; } } class Course { public int Id { get; set; } public string Name { get; set; } public

Select unselected m2m instance in django model form

北战南征 提交于 2019-12-10 11:48:51
问题 I have an Invoice master model and its admin. In the Invoice detail(Inline), I wish to select distinct products from Product table i.e In each Invoice detail, I should not allow to select product that has been previously selected. Can I get sample code for it? Relations defined: models.py: class InvoiceHeader(models.Model): #model number .... class InvoiceDetail(models.Model): header = models.ForeignKey(InvoiceHeader) products = models.ManyToManyField(Product,related_field="products") admin