many-to-many

How to save to Database with associations in rails protecting mass assignment

社会主义新天地 提交于 2019-12-24 22:41:50
问题 After trying for few hours I can not save to the database. The context is this: I have two types of users, one for that I only need very basic information [Username, email, password] and another kind of user for who I need a lot of information [age, gender, city and so on] I did not use STI becouse of the vast quantity of Null values there would be in the table. So I created this three modes in which a user has a profile (profiles table) or not depending of its type [1 or 2], and a field of

django ManyToMany show related objects

南楼画角 提交于 2019-12-24 22:03:16
问题 Searched everywhere but couldn't find anything even though it feels so simple. So basically i have two classes in my models.py class Restaurant(models.Model): restaurant_title = models.CharField(max_length=30) location = CountryField(null=True, blank_label='(select country)') first_purchase_discount = models.BooleanField(default=False) updated = models.DateTimeField(auto_now=True) slug = models.SlugField(max_length=30, unique=True) def save (self, *args, **kwargs): self.slug = slugify(self

Select records which doesn't have specific records in joined table

别来无恙 提交于 2019-12-24 20:41:04
问题 Hi I'm trying to select records from one table which doesn't have records in connected many-to-many table with specific values. I will explain on sample tables: documentation: id_documentation irrelevant_data user: id_user irrelevant_data documentation_user: id_documentation id_user role What I want to achieve is to select every single documentation which doesn't have user in specific role. Any ideas? The main problem is that I'm using java's CriteriaBuilder to create query so using

One INSERT with multiple SELECT

喜你入骨 提交于 2019-12-24 14:02:42
问题 I've already read this, this and this, but I cant make this SQL work: INSERT INTO main_phrase (description) VALUES ('Mot commun féminin pluriel animaux'); /* ERROR: */ WITH t1 AS ( SELECT id FROM main_phrase WHERE description='Mot commun féminin pluriel animaux' ), t2 AS ( SELECT id FROM main_groupecategories WHERE description='Mot commun féminin pluriel animaux' ) INSERT INTO main_phrasegroupecategories (phrase_id, groupe_categories_id) VALUES (t1.id, t2.id); I get: ERROR: missing entry for

grails beforeDelete with many-to many relation

。_饼干妹妹 提交于 2019-12-24 13:30:41
问题 I have 2 domain class with a many to many relationship. When I delete the entity that belongs to the other, I have to remove the relation before in order to avoid a foreign key error. I would like to put this code in the beforeDelete event, but I obtain a problem with optimistc locking. This is the code of the domain classes: class POI { static belongsTo = [Registration]; static hasMany = [registrations: Registration] def beforeDelete = { def poiId = this.id POI.withNewSession { session ->

how to properly define a ManyToMany field in the models.py file

╄→гoц情女王★ 提交于 2019-12-24 13:25:52
问题 In my Django app I have the following models.py: from django.db import models import datetime class Job(models.Model): name = models.CharField(max_length = 250, null = False) user = models.CharField(max_length = 30, null = False) command = models.CharField(max_length = 1000, null = False) whenToRun = models.DateTimeField('Run Date', null = False) output = models.CharField(max_length = 100000, null = True) class Host(models.Model): jobs = models.ManyToManyField(Job, blank = True) name = models

Deleting only one entry from Many-to-Many relationship

…衆ロ難τιáo~ 提交于 2019-12-24 13:25:45
问题 Ok, so i have this problem right now. I have 2 Models like so: public class Contact: BaseModel { public string LastName { get; set; } public string FirstMidName { get; set; } public string Adress { get; set; } public int UserID { get; set; } [Display(Name = "Full Name")] public string FullName { get { return FirstMidName+ " " + LastName; } } public virtual List<Group> Groups { get; set; } public virtual User User { get; set; } public virtual ICollection<Phones> Phones { get; set; } } and also

Many-to-many relationship in SSAS Tabular project

家住魔仙堡 提交于 2019-12-24 13:03:19
问题 I'm trying to set up a many-to-many relationship in SSAS Tabular. I've got the following in my tabular project (sales, customers, customer emails): A sale is tied to a customer. A customer can have multiple emails. How would I create a list of all emails that fit the current filter of a pivot table? For example, I could create a pivot table shows "accounts with margin < 20%", and want a list of all emails associated with those accounts. Sample, starting with the following sales data: customer

How to get entities in a many-to-many relationship that do NOT have a corresponding linked entity with DQL and Doctrine?

☆樱花仙子☆ 提交于 2019-12-24 12:43:53
问题 I have a standard many-to-many relationship set up. Entity A can have many of Entity B, and vice versa . I'm trying to get a list of all Entity A that do NOT have any corresponding Entity B. In SQL, I'd run a query like this: SELECT a.* FROM entity_a a LEFT JOIN a_b r ON r.AID = a.id WHERE r.BID IS NULL In this query, a_b is the linking table. I'm trying to write a DQL statement (or use some other method) to get the same result, but the following does not work: SELECT s FROM VendorMyBundle

Many to many relationship?

冷暖自知 提交于 2019-12-24 11:34:25
问题 Guys I am trying to make a simple ticket generation system for my company as a favor. For now, I have a table called tblTicket and another table called tblEngineer in my MSSQL database. My application is in C# windows forms, so on the new ticket generation form, I have many textboxes and a comboBox for assigning engineer which is being populated by tblEngineer . Upon ticket generation, all the information entered in this form is stored in tblTicket along with EngineerID from tblEngineer . It