many-to-many

Doctrine many-to-many relations and onFlush event

核能气质少年 提交于 2019-12-24 10:56:11
问题 Little example about Books and Authors: DB structure: Entities (they were generated form database using symfony2 console commands): Author: /** * Author * * @ORM\Table(name="authors") * @ORM\Entity */ class Author { private $_isCachable = true; /** * @var integer * * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @var string * * @ORM\Column(name="name", type="string", length=255, nullable=false) */ private

Many-to-many relation ship with form-based multi selection

北城以北 提交于 2019-12-24 10:09:21
问题 I am creating a database and I need to construct a form-based entry method of adding data into my tables, whilst maintaining what I believe is a many-to-many relationship. Say Project X can have Parts X, Y and Z - and Parts X, Y and Z can be used on more than one project. What is the best way of allocating a list of 'parts' to a project through a form, without have a huge array of tickboxes, and how do I construct my tables to accommodate this? Much appreciated. 回答1: Many-to-Many relationship

is distinct an expensive query in django?

谁说我不能喝 提交于 2019-12-24 09:58:15
问题 I have three models: Product, Category and Place. Product has ManyToMany relation with Category and Place. I need to get a list of categories with at least on product matching a specific place. For example I might need to get all the categories that has at least one product from Boston. I have 100 categories, 500 places and 100,000 products. In sqlite with 10K products the query takes ~ a second. In production I'll use postgresql. I'm using: categories = Category.objects.distinct().filter

Entity Framework - many to many with primary key and composite foreign key

坚强是说给别人听的谎言 提交于 2019-12-24 06:43:52
问题 I have two entities (Case and Person) in a many-to-many relationship with an extra data field(CasePerson with PersonType) on the relationship table. public class Case { public int Id; public List<CasePerson> CasePeople; } public class Person { public int Id; public List<CasePerson> CasePeople; } public class CasePerson { public int Id; public int CaseId; public int PersonId; public string Type; public Person Person; public Case Case; } I'd like to create a composite key on the relational

Accessing a join-model attribute stored in a join table created with #create_join_table

≯℡__Kan透↙ 提交于 2019-12-24 04:47:09
问题 In a Rails ( 4.1.5 / ruby 2.0.0p481 / win64 ) application I have a many-to-many relationship between Student and Course and a join model StudentCourse which represents the association, which has an additional attribute called "started", which is set by default on "false". I also have added an index in the join table made of the student_id and the course_id, and set a unique check on that, like this t.index [:student_id, :course_id], :unique => true, :name => 'by_student_and_course' Now I see

Symfony2 form - Many to Many as text causing errors

余生颓废 提交于 2019-12-24 03:50:35
问题 I have tried looking around for a possible solution to this but with no luck. What I have is a Many to many relationship between properties and postcodes, I can't display the postcodes in a select for example due to the amount of possible entries. My solution was to have it as a text field in the form and then catch it on PrePersist to search for the matching record and then apply this to the entity before persisting to the db. The problem is when the form is validating it is still trying to

Access relational data of many to many relationship with multiple database connection with different server

瘦欲@ 提交于 2019-12-24 03:22:06
问题 I'm working with multiple database connection on different servers. i.e, host1 and host2 . My default database connection is host2. My project have two tables. users exists on host1 and tasks exists on host2 . There is a many to many relationship on both tables. Pivot table for this relationship is task_users which exists on host2 . My model files are here. User.php class User extends Authenticatable { protected $connection = 'host1'; public function tasks() { return $this->belongsToMany(Task

How to distuingish between Django's automatically created ManyToMany through-models and manually defined ones?

半腔热情 提交于 2019-12-24 03:13:06
问题 Say we have models: from django.db import models class AutomaticModel(models.Model): others = models.ManyToManyField('OtherModel') class ManualModel(models.Model): others = models.ManyToManyField('OtherModel', through='ThroughModel') class OtherModel(models.Model): pass class ThroughModel(models.Model): pblm = models.ForeignKey('ManualModel') other = models.ForeignKey('OtherModel') After this we can access the through models via AutomaticModel._meta.get_field('others').rel.through and

How to implement a 3 Many-to-Many relationship with Hibernate?

坚强是说给别人听的谎言 提交于 2019-12-24 03:10:53
问题 I'm not 100% sure this is only a Hibernate issue as this might be a more abstract decision but I'll give it a try. Since the problem description is a bit lengthy I'll first state that what I'd like to do is see if I can change the implementation to something which more resembles a Best practice implementation then this. I have 3 entities, relevant to this issue: Workstation (ws), Employee and Organization-unit(org-unit). An Employee can belong to one org-unit. An Org-unit can hold many

Django unique together relationship with field and manytomany on self

百般思念 提交于 2019-12-24 00:43:43
问题 I'm try create post with language and content, and relate it on other versions of same page, but I'm get stuck class Page(models.Model): content = models.TextField() language = models.CharField(max_length=7, choices=settings.LANGUAGES) versions = models.ManyToManyField('self', blank=True) class Meta: unique_together = ('language', 'versions',) This will not work properly, because Django not allow make "unique" ManyToMany fields. Then I'm try make same relationship trough related model: class