many-to-many

stuck with asp.net mvc 3.0 Scaffolding in case of many to many relationship

守給你的承諾、 提交于 2019-11-30 16:11:45
I am working on a mvc3.0 app using EF code first and mvc scaffolding. I am currently stuck with many to many relation between entities. I have following model. namespace BigApp.Models { #region POCO Objects public class Group { public int Id { get; set; } public string Name { get; set; } public DateTime CreatedOn { get; set; } public DateTime UpdatedOn { get; set; } public virtual ICollection<Project> Projects { get; set; } } public class Project { public int Id { get; set; } public string Name { get; set; } public string Url { get; set; } public DateTime CreatedOn { get; set; } public

Save Many-to-Many in Spring MVC

房东的猫 提交于 2019-11-30 16:08:05
I got relation many to many between Restaurant and Tag. Here are my entities: public class Restaurant { @Id @GeneratedValue private int id; (...) @ManyToMany @JoinTable(name="restaurant_tag", joinColumns={@JoinColumn(name="restaurant_id")}, inverseJoinColumns={@JoinColumn(name="tag_id")}) private List<Tag> tags; And: public class Tag { @Id private int id; private String name; @ManyToMany @JoinTable(name="restaurant_tag", joinColumns={@JoinColumn(name="tag_id")}, inverseJoinColumns={@JoinColumn(name="restaurant_id")}) private List<Restaurant> restaurants; In my controller (add) I got: public

How to do a many-to-many relationship in spring Roo, with attributes within de relationship?

自作多情 提交于 2019-11-30 16:06:20
问题 i have been researching on this topic and havent found any answers yet. Im using spring roo and i would like to know if theres a way I can establish a many-to-many relationship with attributes within this relationship. For example i have two tables Employee and MedicalEquipment, Employees can reserve many equipments, and equipment could be reserved by many employee, however i want to store the date this reserve took place. If some one can help i would appreciate it. Thanks in advance! 回答1: In

How to count and display objects in relation ManyToMany in Django

爱⌒轻易说出口 提交于 2019-11-30 16:03:35
I have a simple model with news and categories: class Category(models.Model): name = models.CharField() slug = models.SlugField() class News(models.Model): category = models.ManyToManyField(Category) title = models.CharField() slug = models.SlugField() text = models.TextField() date = models.DateTimeField() I want to count news for each category and display it on the website, like this: Sport (5) School (4) Films (6) Computer (2) etc... How can I do this?? Thanks! Check out annotate() function from Django 1.1. http://docs.djangoproject.com/en/dev/topics/db/aggregation/#topics-db-aggregation

have additional column in ManyToMany join table in Doctrine (Symfony2)

别来无恙 提交于 2019-11-30 16:00:34
问题 Situation I have two entities User and Group with relation ManyToMany. Relation is created as separated table (called user_group ) with two columns user_id and group_id . Problem I want to add one more field addedOn TIMESTAMP DEFAULT CURRENT_TIMESTAMP to table user_group . I do not care that doctrine will not see this column, I could select it via SQL when I need it. Question Can this be done via doctrine configuration ? If yes, how? I know I can just add column in DB but then everytime I

Hibernate Many-to-many association: left hand side collection contains elements, but right hand side collection is empty

▼魔方 西西 提交于 2019-11-30 15:13:39
问题 I got a problem with a many to many association in my persistence layer. My scenario is the following: A user can has several roles and a role can have several user attached to it. During the tests I encountered a strange behavior. I created role object and several user objects. The role was set to each of the users. After this the users were saved using a DAO. Then one of the user gets loaded to check whether he got the role that was passed to him before saving the user object. Calling

Efficiently delete orphaned m2m objects/tags in Django

妖精的绣舞 提交于 2019-11-30 15:13:35
I have two models - Photo and Tag - which are connected via a ManyToManyField. class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model): lang = models.CharField(max_length=2) name_es = models.CharField(max_length=40) name_en = models.CharField(max_length=40) Every once in a while, we get orphaned tags, that are not referenced any more by any photo. Is there an efficient way of deleting those tags? I know about this answer: Django: delete M2M orphan entries? And our solution looks like this at the moment: for tag in Tag.objects.all(): if not tag.photo_set.select

Automapper - Bestpractice of mapping a many-to-many association into a flat object

落花浮王杯 提交于 2019-11-30 15:07:46
I have two entities: Employee and Team . What I want is an EmployeeForm that has the Name of the Team . How can I achieve this using AutoMapper ? My current "solution" is the following: Mapper.CreateMap<Employee, EmployeeForm>() .ForMember(dest => dest.TeamName, opt => opt.MapFrom(x => x.GetTeams().FirstOrDefault() != null ? string.Join(", ", x.GetTeams().Select(y=>y.Name)) : "n/a")); In my opinion this is bad readable. What I would like to have is a generic method where I can pass an entity, choosing the collection and saying if collection is null return a default value or otherwise choose

Save a many-to-many model in Django/REST?

自作多情 提交于 2019-11-30 14:38:09
I'm writing a REST API for my Django app, and can't get POST requests to work on one model. Here's the model in question: class ProjectNode(models.Model): name = models.CharField(max_length=60) place = models.CharField(max_length=150) time_spent = models.BigIntegerField() parent_project = models.ForeignKey(Project, related_name='tasks') workers = models.ManyToManyField(User, related_name='tasks_can_do') def __str__(self): return self.name The User model just holds a name field at the moment. Here's my serializer for ProjectNode : class ProjectNodeSerializer(serializers.ModelSerializer): class

Undelete an entity marked as EntityState.Delete?

匆匆过客 提交于 2019-11-30 14:01:32
instead of talking let me talk with code: Dim Contact = Context.Contacts.Include("Phones") Dim phone = Contact.Phones(0) Contact.Remove(phone) How do I refresh the context now, canceling last relation deletion? I tried: Context.Refresh(RefreshMode.StoreWins, phone) 'Doesn't recover the relation Context.Refresh(RefreshMode.StoreWins, _ ObjectStateManager.GetObjectStateEntries(EntityState.Deleted)) the last one throws an InvalidOperationException: The element at index 0 in the collection of objects to refresh has a null EntityKey property value or is not attached to this ObjectStateManager.