many-to-many

Eloquent filter on pivot table created_at

橙三吉。 提交于 2019-12-31 07:35:08
问题 I want to filter the contents of two tables which have an Eloquent belongsToMany() to each other based on the created_at column in the pivot table that joins them. Based on this SO question I came up with the following: $data = ModelA::with(['ModelB' => function ($q) { $q->wherePivot('test', '=', 1); }])->get(); Here I'm using a simple test column to check if it's working, this should be 'created_at'. What happens though is that I get all the instances of ModelA with the ModelB information if

Return all nodes in many-to-many hierarchal tree

扶醉桌前 提交于 2019-12-31 07:25:09
问题 Similar to this question: How do I query for all the nodes between two nodes in a tree? But I do not have a closure (flattened) table, a child can have many parents, and ID traversal is not necessarily in order. There is no limit to the nesting depth. Assume a circular reference is impossible... I would like to return all rows required to traverse the hierarchy. Assume the following table: ParentID ID RowNumber(Reference) 1 2 1 2 4 2 4 3 3 3 5 4 1 6 5 6 7 6 2 8 7 3 9 8 1 8 9 6 8 10 Given 1

how to query a many to many relationship?

房东的猫 提交于 2019-12-30 12:38:12
问题 I'm trying to build an e-learning platform I have users (Utilisateur) who can take several courses ,each course have several modules and a module can be in several courses A user can be a student or teacher or admin, a student is "managed" by a teacher or several and a teacher can also be managed by a teacher (if he is a researcher) ,teachers are managed by admins I'm not familiar with many_to_many concept, please correct me This is my django models : class Utilisateur(models.Model): user =

How do I use a TabularInline with editable fields on a ManyToMany relationship?

纵然是瞬间 提交于 2019-12-30 08:50:10
问题 My models contain a many-to-many relationship. Measurements can be part of any number of DataSets . # models.py from django.db import models class DataSet(models.Model): purpose = models.TextField() class Measurement(models.Model): value = models.IntegerField() sets = models.ManyToManyField(DataSet, null=True, blank=True, verbose_name="datasets this measurement appears in") I want my admin interface to inlines Measurement fields in the DataSet admin like how a TabularInline works with a

Django admin interface: using horizontal_filter with ManyToMany field with intermediate table

為{幸葍}努か 提交于 2019-12-30 07:10:26
问题 I am trying to enhance the django admin interface similar to what has been done in the accepted answer of this SO post. I have a many-to-many relationship between a User table and a Project table. In the django admin, I would like to be able to assign users to a project as in the image below: It works fine with a simple ManyToManyField but the problem is that my model uses the through parameter of the ManyToManyField to use an intermediary table. I cannot use the save_m2m() and set() function

Drop-Down-Menu for Many-to-Many relation in rails using nested attributes

隐身守侯 提交于 2019-12-30 05:24:08
问题 I have three tables via many-to-many-association: Supermarket, Product and Supply. Each Supermarket can hold many products and each product can be sold in many supermarkets. The association is build via the Supply-model. Supermarket: class Supermarket < ActiveRecord::Base attr_accessible :name, :address, :products_attributes has_many :supplies has_many :products, :through => :supplies accepts_nested_attributes_for :products end Product: class Product < ActiveRecord::Base attr_accessible :name

How to add column in ManyToMany Table (Django)

泄露秘密 提交于 2019-12-30 01:37:16
问题 From the example of Django Book, I understand if I create models as following: from xxx import B class A(models.Model): b = ManyToManyField(B) The Django would create a new table(A_B) beyond Table A, which has three columns: id a_id b_id But now I want to add a new column in the Table A_B, thus would be very easy if I use normal SQL, but now anyone can help me how to do? I can't find any useful information in this book. 回答1: It's very easy using django too! You can use through to define your

how to query many-to-many?

百般思念 提交于 2019-12-29 21:06:29
问题 I found the following table structures while I was watching ruby on rails tutorial. table actors id int 11 primary key auto_increment name varchar 30 table movies id int 11 primary key auto_increment name varchar 30 table actors_movies actor_id int 11 movie_id int 11 How do I make a query to select movies that an actor is involved in? I am not asking for ruby on rails code. I want the actual mysql query string. Thank you! 回答1: one thing to consider is that you are going to load the author

Doctrine 2 - Log changes in manyToMany relation

女生的网名这么多〃 提交于 2019-12-29 18:49:12
问题 I use Loggable behavioral extension to log changes in my entities. I want to log changes in manyToMany relations too. I want to show to user this kind of change log: +--------------------------------------------------+ | Article "My Article" change log: | +-------+------------+-----------------------------+ | Who | When | What | +-------+------------+-----------------------------+ | Admin | 2015-07-01 | Removed tags "tag1", "tag2" | | Admin | 2015-07-01 | Added tags "tag3" | +-------+--------

Inserting multiple entities into many-to-many linking table

时光总嘲笑我的痴心妄想 提交于 2019-12-29 10:00:12
问题 My web application has a many-to-many link between the Station and Timetable entities, and the entity that links them is called StationTimetable , which also holds data about the linkage between the two entities. When I create a new Timetable , I want to create new (and multiple) StationTimetable entries in the database to correspond to this new Timetable . So far I've managed to get the application to save just one StationTimetable entry when the user creates a new timetable. I sort of