many-to-many

Proper way to update bidirectional Many to Many relationship symfony2-doctrine

坚强是说给别人听的谎言 提交于 2019-11-28 11:34:34
I did some research, and after reading this and this (and all the related questions) I still can't figure which is the proper way to update a many to many relationship in Symonfy 2 Doctrine. It feels that there should be a very simple way of doing it that I still haven't found. I have this 2 entities: class student_main { /** * @ORM\ManyToMany(targetEntity="support_log", inversedBy="student_main") * @ORM\JoinTable(name="support_log_student") **/ private $support_log; and class support_log { /** * @ORM\ManyToMany(targetEntity="student_main", mappedBy="support_log") **/ private $student; I want

Entity Framework Database First many-to-many

倖福魔咒の 提交于 2019-11-28 11:33:12
I've created an Entity Framework model from the database. I have many-to-many relationship: User - UserRole - Role . EF created UserRole entity and UserRoles navigation property in the User entity and in Role entity, but I'd rather have Roles in User and Users in Role . Is that possible to be designed through the Model Designer? How can I configure manually many-to-many relationship with a table in the middle? EF normally creates the intermediate model, if the UserRole table comprises of columns other than foreign keys for User and Role table. So if you had just 2 columns in the UserRoles

Core Data: Predicate for first element in orderd relationship

六月ゝ 毕业季﹏ 提交于 2019-11-28 10:07:29
问题 I have this to-many relationship which contains at least one element: Appointment <<------>> Invitee appointment.invitees is an ordered relationship resulting in an NSOrderedSet . In a table view controlled by a fetched results controller, I have the appointments listed, along with the first element of the invitees set. Now I want to search this list by invitees' names, using an NSPredicate . But how can refer to the first element of the ordered list in the predicate? I tried: fetchRequest

Removing many to many reference in Mongoose

霸气de小男生 提交于 2019-11-28 09:17:02
One of my mongoose schemas is a many to many relationship: var UserSchema = new Schema({ name : String, groups : [ {type : mongoose.Schema.ObjectId, ref : 'Group'} ] }); var GroupSchema = new Schema({ name : String, users : [ {type : mongoose.Schema.ObjectId, ref : 'User'} ] }); If I remove a group, is there anyway to remove that group objectId from all the user's 'groups' array? GroupSchema.pre('remove', function(next){ //Remove group._id from all the users }) You're on the right track to use 'remove' middleware for this. In the middleware function, this is the group instance being removed

Class-based views for M2M relationship with intermediate model

爱⌒轻易说出口 提交于 2019-11-28 08:48:10
I have a M2M relationship between two Models which uses an intermediate model. For the sake of discussion, let's use the example from the manual: class Person(models.Model): name = models.CharField(max_length=128) def __unicode__(self): return self.name class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(Person, through='Membership') def __unicode__(self): return self.name class Membership(models.Model): person = models.ForeignKey(Person) group = models.ForeignKey(Group) date_joined = models.DateField() invite_reason = models.CharField(max_length

Many-to-many on the same table with additional columns

瘦欲@ 提交于 2019-11-28 07:02:09
I have a class User. A user can be a friend with many other users. The relationship is mutual. If A is a friend of B then B is a friend of A. Also I want every relation to store additional data - for example the date when two users became friends. So this is a many-to-many relationship on the same table with additional columns. I know that a middle class Friendship should be created(containing two user ids and column for the date). But I am coming short at mapping this with Hibernate. The thing that stops me is that the mapping is to the same table. I can solve it, if the many-to-many

SQLite many-to-many relationship?

梦想与她 提交于 2019-11-28 06:54:34
I'm trying to set up a SQLite3 database with foo s and bar s and a many-to-many relation between them. This is what I've got so far: CREATE TABLE foo( id INTEGER PRIMARY KEY NOT NULL, foo_col INTEGER NOT NULL ); CREATE TABLE bar( id INTEGER PRIMARY KEY NOT NULL, bar_col TEXT NOT NULL ); CREATE TABLE foobar( foo_id INTEGER, bar_id INTEGER, FOREIGN KEY(foo_id) REFERENCES foo(id) ON DELETE CASCADE, FOREIGN KEY(bar_id) REFERENCES bar(id) ON DELETE CASCADE ); CREATE INDEX fooindex ON foobar(foo_id); CREATE INDEX tagindex ON foobar(tag_id); ...but it doesn't seem to be working. I can delete a row

How to model a Many to many-relationship in code?

夙愿已清 提交于 2019-11-28 06:48:43
Suppose I have 2 tables in a database. eg: Dog & Boss This is a many to many relationship, cause a boss can have more than 1 dog, and a dog can have more than 1 owner. I am the owner of Bobby, but so is my wife. But many to many is not allowed, so there is a helpertable: DogsPerBoss How to model this in code? Class Boss can have a collection of Dogs. Class Dog can have a collection of Bosses. --> at least, that is what I think. Perhaps there are better solutions? How about extra data that is in the helper-table? Should that be in de Boss-class or in the Dog-class? eg: Nickname (I call the dog

Core Data Many-to-Many Relationship NSPredicate

早过忘川 提交于 2019-11-28 06:37:51
问题 I have a data model with a many-to-many relationship like EntityA <-->> EntityB <<--> EntityC . I used to query EntityA with different search criteria and I use NSCompoundPredicate with an array of NSPredicate s. On one of the predicate I wanted to query EntityA using EntityC . I tried to use the following SUBQUERY but it did not work. searchPredicate=[NSPredicate predicateWithFormat:@"(0 != SUBQUERY(EntityB, $B, (0 != SUBQUERY($B.EntityC, $EntityC, $EntityC.name like %@).@count)).@count)",

How to have a foreign key pointing to two primary keys?

房东的猫 提交于 2019-11-28 06:31:23
问题 I'm trying to simplify a database structure, and I have two tables matches and team_statistics : Here in the team_statistics table the team_statistics.team_id should be a foreign key that references matches.teams_id and matches.teams_id1 and similarly team_statistics.group_id should be a foreign key referencing matches.groups_id and matches.groups_id1 How to do this in PostgreSQL? If there are other ways of doing this by having another table between matches and team_statistics I'm open for