many-to-many

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

强颜欢笑 提交于 2019-12-05 06:21:13
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' }, roles: { collection: 'role', via: 'users', through: 'policy' }, } } //Role.js module.exports = { tableName

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

十年热恋 提交于 2019-12-05 06:08:04
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") * @ORM\Entity(repositoryClass="LA\AdminBundle\Entity\ExamRepository") */ class Exam { ... /** * @ORM

Updating in a many-to-many relationship

感情迁移 提交于 2019-12-05 05:43:40
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? 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 belong to a few roles (less than 10). Also, there is a good chance that no other foreign-keys link to this many

Entity Framework 4 Code-First many to many insert

两盒软妹~` 提交于 2019-12-05 05:39:25
问题 I'm using code-first pattern for database layer. I have two POCO classes: public class Order { [Key] public int OrderId { get; set; } public virtual ICollection<Item> Items { get; set; } // other fields } and public class Item { [Key] public int ItemId { get; set; } public virtual ICollection<Order> Orders { get; set; } // other fields } Then I have data context class: public class DataContext : DbContext { public DbSet<Item> Items { get; set; } public DbSet<Order> Orders { get; set; } } And

How can I build/create a many-to-many association in factory_girl?

ぃ、小莉子 提交于 2019-12-05 05:09:19
问题 I have a Person model that has a many-to-many relationship with an Email model and I want to create a factory that lets me generate a first and last name for the person (this is already done) and create an email address that is based off of that person's name. Here is what I have for create a person 's name: Factory.sequence :first_name do |n| first_name = %w[FirstName1 FirstName2] # ... etc (I'm using a real subset of first names) first_name[(rand * first_name.length)] end Factory.sequence

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

和自甴很熟 提交于 2019-12-05 04:02:19
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.Id; order.Contact.Attach(contact); // throws an exception! OrderDetails ordTable = new OrderDetails();

EF repository pattern many to many insert

ε祈祈猫儿з 提交于 2019-12-05 02:59:19
问题 We have 2 tables: Table Authority: public class Authority { public int ID {get;set;} public string Name{get;set;} ... } Table Agents public class Agent { public int ID{get;set;} public int FirstName{get;set;} } And we have a relationship many-to-many between these two tables: public class AuthorityConfiguration : EntityTypeConfiguration<Authority> { public AuthorityConfiguration() : base() { HasKey(p => p.ID); HasMany(p => p.Agents).WithMany(a => a.Authorities).Map(mc => { mc.MapLeftKey(

many to many table with an extra column in Rails

强颜欢笑 提交于 2019-12-05 02:58:44
问题 Hi guys! Is possible to do this with only two Rails models, User and Event: Users |id |name |age | |1 |danilo |26 | |2 |joe |23 | |3 |carlos |50 | |4 |katy |45 | Events_Users |event_id |user_id |confirmed | |1 |1 |1 | |3 |3 |0 | |4 |3 |1 | |2 |3 |1 | Events |id |name |date | |1 |the end of the year |31/12/2012 | |2 |the end of the world |21/12/2012 | |3 |Party |18/12/2012 | |4 |Dinner |19/12/2012 | The problem is, the user can confirm or not their presence in an event, for this I used the

Maintaining both sides of self-referential many-to-many relationship in Grails domain object

試著忘記壹切 提交于 2019-12-05 02:46:05
问题 I'm having some problems getting a many-to-many relationship working in grails. Is there anything obviously wrong with the following: class Person { static hasMany = [friends: Person] static mappedBy = [friends: 'friends'] String name List friends = [] String toString() { return this.name } } class BootStrap { def init = { servletContext -> Person bob = new Person(name: 'bob').save() Person jaq = new Person(name: 'jaq').save() jaq.friends << bob println "Bob's friends: ${bob.friends}" println

ManyToMany Relation with Play Framework 1.2.5 JPA

删除回忆录丶 提交于 2019-12-05 02:44:44
问题 I have 2 Models Article.java and Tags.java . An Article can have many Tags , and a Tags can be belonged to many Article . I am really in trouble to make this relation using JPA and Play Framework 1.2.5. Below are my codes (without setter-getter), and actually it works even throwing exception but I can not get the Tags ( getTagname() ) of an Article Article article = Article.findById((long)id); List<Tags> tags = article.getTags(); for (Tags tags2 : tags) { System.out.println(tags2.getTagname()