many-to-many

manytomany relation not able to save mapped id in mapping table in play framework

半腔热情 提交于 2019-12-05 21:01:21
I am using play2.2.1 and trying to create a ManyToMany relation between Jobads and JobCategory models. My Jobads.java package models; @Entity public class Jobads extends Model { @Id public Long id; @ManyToOne public Employers employer; @ManyToMany(cascade = CascadeType.ALL) @JoinTable(name = "jobads_jobcategories") public List<Jobcategories> jobcategory; @ManyToOne public Joblocations joblocations; @Required public String jobtype; @Required public String title; @Required public String text; @Required public Long salary; @Required public String experience; @Required public String active;

Django, in many to many relationship within the self class, how do I reference each other in terms of ORM?

回眸只為那壹抹淺笑 提交于 2019-12-05 20:44:51
class User(models.Model): name = models.CharField(max_length=100) age = models.IntegerField() gender = models.IntegerField() email = models.CharField(max_length=100) password = models.CharField(max_length=255) following = models.ManyToManyField("self", related_name='followers') objects = UserManager() def __repr__(self): return "User: {0}".format(self.name) In my model, User, users can follow and followed by each other. I can find who the user is following by this: user1 = User.objects.get(id=1) following = user1.following.all() However, I can't figure out how to find whom the user is followed

how to map Many to Many with composite key

爷,独闯天下 提交于 2019-12-05 18:47:00
I have the following tables Trainingplan TrainingplanID int(11) AI PK Trainer int(11) Client int(11) validFrom date validTo date type int(11) TrainingplanExercises trainingplan int(11) PK exercise int(11) PK parameter int(11) PK value varchar(45) No I have problems connecting them with Hibernate. I did the following: package beans; @Entity @Table(name = "Trainingplan") public class Training { private IntegerProperty id; private ObjectProperty<Person> client; private ObjectProperty<Person> trainer; private ObjectProperty<Date> validFrom; private ObjectProperty<Date> validTo; private

Generic trigger to restrict insertions based on count

你离开我真会死。 提交于 2019-12-05 15:45:31
Background In a PostgreSQL 9.0 database, there are various tables that have many-to-many relationships. The number of those relationships must be restricted. A couple of example tables include: CREATE TABLE authentication ( id bigserial NOT NULL, -- Primary key cookie character varying(64) NOT NULL, -- Authenticates the user with a cookie ip_address character varying(40) NOT NULL -- Device IP address (IPv6-friendly) ) CREATE TABLE tag_comment ( id bigserial NOT NULL, -- Primary key comment_id bigint, -- Foreign key to the comment table tag_name_id bigint -- Foreign key to the tag name table )

Django select objects with empty ManyToManyField

ぐ巨炮叔叔 提交于 2019-12-05 13:00:24
Considering the following models, knowing a family, how do I select Kids with no buyers? class Family... class Kid(models.Model): name = models.CharField(max_length=255) family = models.ForeignKey(Family) buyer = models.ManyToManyField(Buyer, blank=True, null=True) family = get_object_or_404(Family, pk=1) for_sale = family.kid_set.filter(buyer... this screws my child trade business family.kid_set.filter(buyer__isnull=True) should work. Manoj Govindan @piquadrat's answer is correct. You can also do: for_sale = Kid.objects.filter(family__pk = 1, buyer = None) This lets you avoid a separate query

Save M2M “Through” Inlines in Django Admin

孤街浪徒 提交于 2019-12-05 12:47:58
Apparently Django's ModelAdmin/ModelForm doesn't allow you to use save_m2m() if there's an intermediate through table for a ManyToManyField. models.py: from django.db import models def make_uuid(): import uuid return uuid.uuid4().hex class MyModel(models.Model): id = models.CharField(default=make_uuid, max_length=32, primary_key=True) title = models.CharField(max_length=32) many = models.ManyToManyField("RelatedModel", through="RelatedToMyModel") def save(self, *args, **kwargs): if not self.id: self.id = make_uuid() super(GuidPk, self).save(*args, **kwargs) class RelatedModel(models.Model):

What's the optimal solution for tag/keyword matching?

别说谁变了你拦得住时间么 提交于 2019-12-05 11:03:08
I'm looking for the optimal solution for keyword matching between different records in the database. It's a classic problem, I've found similar questions, but nothing concretely. I've done it with full text searches, joins and subqueries, temp tables, ... so i'd really like to see how you guys are solving such a common problem. So, let's say I have two tables; Products and Keywords and they are linked with the third table, Products_Keywords in a classic many-to-many relationship. If I show one Product record on the page and would like to show top n related products, what would be the best

Query for a ManytoMany Field with Through in Django

不问归期 提交于 2019-12-05 08:09:16
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=2, max_digits=10) The idea being that there will be a set of fees associated with each Activity and

Multiple select edit form selected values

余生颓废 提交于 2019-12-05 07:56:33
Struggling with an issue in Laravel 4, in a "contact" model edit form, I can get all fields current values except those from the multiple select which is to establish a relation with another model "company". It's a many-to-many relationship. I'm getting the list of companies, but none are selected even if a relation exists. Here's my edit form: {{ Form::model($contact, array('route' => array('crm.contacts.update', $contact->id), 'id' => 'edit-contact')) }} <div class="control-group"> {{ Form::label('first_name', 'First Name', array( 'class' => 'control-label' )) }} {{ Form::text('first_name')

Empty Join Table resulting from JPA ManyToMany

时光总嘲笑我的痴心妄想 提交于 2019-12-05 07:30:47
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", nullable = false) private Long camId; @Column(name="CAMERA_BRAND") private String cameraBrand;