many-to-many

Sails.js + Waterline: Many-to-Many through association

 ̄綄美尐妖づ 提交于 2019-12-07 03:09:31
问题 I'm new to Sails.js (v0.10.5) and Waterline ORM. I have 3 tables in database: users (id, name), roles(id, alias) and join table users_roles(user_id, role_id). It's important not to change table names and field names in database. I want Policy entity to be a join entity between User and Role. Here is some mapping code: //User.js module.exports = { tableName: 'users', autoCreatedAt: false, autoUpdatedAt: false, attributes: { id: { type: 'integer', required: true }, name: { type: 'string' },

Get entities from a unidirectional many to many relation with Doctrine2 and Symfony2

送分小仙女□ 提交于 2019-12-07 02:49:05
问题 I'm currently working on a language assessment project which enables you to take an exam in the language you want and evaluate your level. I use Symfony2 framework and work with Doctrine2 as well. My issue is the following one: I have two entities Exam and Question linked by a Many-To-Many relation (Exam being the owner). Each exam can be related to several questions, and each question can be related to several exams. Here is my code: Exam entity /** * Exam * * @ORM\Table(name="cids_exam") *

Laravel 4 Relationship: messaging system

核能气质少年 提交于 2019-12-07 02:38:31
I followed the suggestions from user ehp in order to build a lightweight messaging-system: https://stackoverflow.com/a/18717864/1084315 Users: id | username Messages: id | from | content user_messages: user_id | message_id class User extends Eloquent { public function messages() { return $this->belongsToMany('Message'); } public function sent_messages() { return $this->hasMany('Messages', 'from'); } } class Message extends Eloquent { public function from() { return $this->belongsTo('User', 'from'); } public function to() { return $this->belongsToMany('User'); } } I create a message like this:

Empty Join Table resulting from JPA ManyToMany

青春壹個敷衍的年華 提交于 2019-12-07 02:25:24
问题 I have an application in which I am trying to implement ManyToMany relation between 2 entities using Hibernate as my JPA provider. The example I am trying is an uni-directional one, wherein a Camera can have multiple Lenses and Lense can fit into multiple Cameras. Following is my entity class...(Just pasting the relevant part of it) Camera: @Entity @Table(name = "CAMERAS") public class Camera implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "CAM_ID"

Query for a ManytoMany Field with Through in Django

﹥>﹥吖頭↗ 提交于 2019-12-07 01:57:06
问题 I have a models in Django that are something like this: class Classification(models.Model): name = models.CharField(choices=class_choices) ... class Activity(models.Model): name = models.CharField(max_length=300) fee = models.ManyToManyField(Classification, through='Fee') ... class Fee(models.Model): activity = models.ForeignKey(Activity) class = models.ForeignKey(Classification) early_fee = models.IntegerField(decimal_places=2, max_digits=10) regular_fee = models.IntegerField(decimal_places

Updating in a many-to-many relationship

廉价感情. 提交于 2019-12-07 00:04:39
问题 I have a many-to-many table that stores a record for each allowed role a user can have. If a user updates his roles (add, and removes) roles how should I handle this? Should I delete all the users roles first and then add the selected ones? Or do some sort of matching? 回答1: There are many ways to skin this cat, a few techniques I can think of: 1. Delete all roles and re-insert This is a straight-forward approach. Remove all the roles for the user and just re-insert. Normally the user only

Using the entity framework to add existing entities to a collection on a newly created entity

无人久伴 提交于 2019-12-06 22:28:22
问题 I am using the Entity framework to create a new order. The order contains a collection of contacts, a many to many relationship. I want to add a reference to an existing contact on the order on creation of the order. Both Order and Contact a Entity Objects. Order order = new Order(); //set details on order Contact contact = new Contact(); EntityKey contactKey = new EntityKey("OrderDetails.Contact", "contact_id", contact.Key.Id); contact.EntityKey = contactKey; contact.contact_id = contact.Key

Entity Framework 4.1 Code First approach to create many-to-many relation

旧时模样 提交于 2019-12-06 21:32:29
问题 I'm using the Silverlight 5 Beta SDK and the EntityFramework 4.1 in an Silverlight Application. I'll try to create the two tables 'Author' and 'Book'. In SQL, there should be a third (join) table, which makes the many-to-many relation between Author and Book (one author could have written many books and a book could be written from many authors). This is what I've got so far: namespace CodeFirst.Models.Web { public class Author { public Author() { this.Books = new HashSet<Book>(); }

Fluent-NHibernate many-to-many cascade does not populate the link table

谁说我不能喝 提交于 2019-12-06 19:37:39
问题 OK, no matter how I define these mappings, my many-to-many mapping does not want to work with cascade insert. I have tried various combination of Cascade() with Reverse() and removing all unnecessary properties just to understand if they had anything to do with this not working, but no lock. It is really Simple stuff: I have a Message (like an email) which is sent from a user (I have called the entity BasicUser ) to a number of users (through property To ). User and Message in terms of

Is @ManyToMany(mappedBy = … ) + @OrderColumn supported by the JPA?

随声附和 提交于 2019-12-06 19:37:38
问题 I have an entity mapped as following: @Entity @Table(name = "Groups") @IdClass(value = GroupId.class) public class Group implements Serializable { @Id @Column(name = "round_id") private Integer roundId; @Id @Column(name = "ordinal_nbr") private Integer ordinalNbr = 0; ... } It has a composite key (round_id, ordinal_nbr) to indicate the order of groups in a round. Now imagine a join table containing entities that link the ordered groups via a self reference (from Group to Group): CREATE TABLE