many-to-many

Laravel Eloquent ORM - Many to Many Delete Pivot Table Values left over

两盒软妹~` 提交于 2019-11-29 00:42:43
问题 Using Laravel, I have the following code $review = Review::find(1); $review->delete(); Review has a many to many relationship defined with a Product entity. When I delete a review, I'd expect it to be detached from the associated products in the pivot table, but this isn't the case. When I run the code above, I still see the linking row in the pivot table. Have I missed something out here or is this the way Laravel works? I'm aware of the detach() method, but I thought that deleting an entity

Hibernate @ManyToMany delete relation

社会主义新天地 提交于 2019-11-29 00:28:51
I have 2 entities: User and UsersList. @Entity @Table(name = "USERS") public class User { @Id @GeneratedValue @Column(name = "ID") private Long id; @ManyToMany(cascade = CascadeType.REMOVE, mappedBy = "users") private List<UsersList> usersLists = new ArrayList<UsersList>(); public List<UsersList> getUsersLists() { return usersLists; } public void setUsersLists(List<UsersList> usersLists) { this.usersLists = usersLists; } } and @Entity @Table(name = "USERS_LIST") public class UsersList { @Id @GeneratedValue @Column(name = "ID") private Long id; @ManyToMany private List<User> users = new

Many-to-many data structure in Python

拟墨画扇 提交于 2019-11-29 00:01:21
I have a data set of books and authors, with a many-to-many relationship. There are about 10^6 books and 10^5 authors, with an average of 10 authors per book. I need to perform a series of operations on the data set, such as counting the number of books by each author or deleting all books by a certain author from the set. What would be a good data structure that will allow fast handling? I'm hoping for some ready made module that can provide methods along the lines of: obj.books.add(book1) # linking obj.books[n].author = author1 obj.authors[m].author = book1 # deleting obj.remove(author1) #

Entity Framework 4 CTP 5 Self Referencing Many-to-Many

巧了我就是萌 提交于 2019-11-28 23:54:03
I have the following scenario in my database. It is a record of Studies and those studies have other studies as prerequisites. In my DB design, it looks like this: And my code looks something like this: public class Study { public int ID { get; set; } public string Topic { get; set; } public byte TypeID { get; set; } public virtual StudyType Type { get; set; } public bool Deprecated { get; set; } public virtual ICollection<Study> Prerequisites { get; set; } } public class StudyType { public byte ID { get; set; } public string Name { get; set; } public virtual ICollection<Study> Studies { get;

Deleting record in many-to-many table

南楼画角 提交于 2019-11-28 23:15:37
I'm following the security chapter of the Symfony 2 book. There's is an example with a table USERS and GROUPS . There is a many-to-many relationship between USERS and GROUPS , which creates in the database a table called USERGROUPS . What I want is to delete a record from USERGROUPS , for example: DELETE from USERGROUPS WHERE user_id = 1 and group_id = 1 I don't know how to do this since I don't have an USERGROUPS.php table file. Using DQL, for example, I want to be able to do this: $em = $this->getDoctrine()->getEntityManager(); $query = $em->createQuery( 'DELETE FROM AcmeStoreBundle

SQL many to many select

孤人 提交于 2019-11-28 22:22:20
问题 category_product --------------- id_category id_product product --------------- id_product id_manufacturer manufacturer --------------- id_manufacturer name How would I create an SQL query so that it selects all the names from manufacturer when id_category is equal to something? 回答1: It's a straightforward inner join of the tables: SELECT m.name, cp.id_category FROM manufacturer as m INNER JOIN product as p ON m.id_manufacturer = p.id_manufacturer INNER JOIN category_product as cp ON p.id

SQLAlchemy: filter by membership in at least one many-to-many related table

不问归期 提交于 2019-11-28 21:18:34
Using SQLAlchemy 0.7.1 and a MySQL 5.1 database, I've got a many-to-many relationship set up as follows: user_groups = Table('user_groups', Base.metadata, Column('user_id', String(128), ForeignKey('users.username')), Column('group_id', Integer, ForeignKey('groups.id')) ) class ZKUser(Base, ZKTableAudit): __tablename__ = 'users' username = Column(String(128), primary_key=True) first_name = Column(String(512)) last_name = Column(String(512)) groups = relationship(ZKGroup, secondary=user_groups, backref='users') class ZKGroup(Base, ZKTableAudit): __tablename__ = 'groups' id = Column(Integer,

SQL JOIN many-to-many

大兔子大兔子 提交于 2019-11-28 21:15:12
Sorry about the minimalistic title but I don't know how to describe it in short. I have three tables: The table of groups ID | Genre ----------------- 1 | Action 2 | Adventure 3 | Drama Many to many table GroupID | ElementID ----------------- 3 | 1 1 | 2 2 | 2 2 | 3 3 | 3 And the table of elements ID | Element ----------------- 1 | Pride and Prejudice 2 | Alice in Wonderland 3 | Curious Incident Of A Dog In The Night Time All is fine and very simple. The SELECT I am trying to achieve is the following ID | Element | Genre ------------------------------------------------------------- 1 | Pride

a new object was found through a relationship that was not marked cascade PERSIST

怎甘沉沦 提交于 2019-11-28 21:07:19
In trying to get a @OneToMany relationship between Article and HeaderField I probably have the mapping not quite right, resulting in: init: Deleting: /home/thufir/NetBeansProjects/USENET/build/built-jar.properties deps-jar: Updating property file: /home/thufir/NetBeansProjects/USENET/build/built-jar.properties compile: run: DEBUG: nntp: newsrc loading /home/thufir/.newsrc DEBUG: nntp: newsrc load: 1 groups in 31ms [EL Info]: 2012-07-31 02:05:05.677--ServerSession(8979162)--EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504 [EL Info]: 2012-07-31 02:05:06.778-

How to update foreign key value in mysql database

萝らか妹 提交于 2019-11-28 19:21:21
问题 I have three tables: categories, languages and categories_languages. Categories_languages is many to many table which links together categories and languages. I would like to update a foregin key value in table languages but it throws me error #1451 - Cannot delete or update a parent row: a foreign key constraint fails! CREATE TABLE IF NOT EXISTS `categories` ( `id` int(11) unsigned NOT NULL auto_increment, `name` varchar(20) NOT NULL, `modified` int(10) unsigned NOT NULL, PRIMARY KEY (`id`),