many-to-many

Has and Belongs to Many error - *_development.hunts_tasks' doesn't exist:

送分小仙女□ 提交于 2019-12-01 01:03:40
So I'm working on a project where there are tasks that make up a scavenger hunt. So when a user clicks on a particular hunt, I'd like the show.html.erb file to show the hunt as well as the tasks associated with that hunt. Both models (Hunt.rb and Task.rb) have "has_and_belongs_to_many" relationships with one another. My controller originally had this code, but it showed every task in the database, instead of just the tasks associated with a particular hunt. def show @hunt = Hunt.find(params[:id]) @title = @hunt.name @tasks = Task.paginate(:page => params[:page]) end So I tried this. def show

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

一世执手 提交于 2019-12-01 01:00: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 and I am clueless on how to adapt the code below to make it work. The model: class UserProfile(models

How to create relationship many to many in SQLAlchemy (python, flask) for model User to itself

你说的曾经没有我的故事 提交于 2019-11-30 22:21:15
I need to create a table called friends , it should looks like: friends: user_id friend_id I was trying to do this with tutorials from SQLALchemy, but I have not found how to make relation many-to-many for same table. Here's what I have tried: # friends table # many to many - user - user _friends = db.Table('friends', db.Column('user_id', db.Integer, db.ForeignKey('users.id')), db.Column('friend_id', db.Integer, db.ForeignKey('users.id')) ) class User(db.Model, UserMixin): # table name in database __tablename__ = 'users' # primary key for table in db id = db.Column(db.Integer, primary_key=True

Selecting an item matching multiple tags

非 Y 不嫁゛ 提交于 2019-11-30 20:28:57
This seems very basic but I can't figure it out. I've got a table "item_tags", and I want to select all of the items that match tags 1 and 2 (as in, each item has to have both tags). How would I do this in mysql? Create table is: CREATE TABLE `item_tags` ( `uid_local` int(11) NOT NULL DEFAULT '0', `uid_foreign` int(11) NOT NULL DEFAULT '0', `sorting` int(11) NOT NULL DEFAULT '0', KEY `uid_local` (`uid_local`), KEY `uid_foreign` (`uid_foreign`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Thanks! Use: SELECT i.uid FROM ITEMS i JOIN ITEM_TAGS it ON it.uid_local = i.uid AND it.uid_foreign IN (1, 2)

Has and Belongs to Many error - *_development.hunts_tasks' doesn't exist:

扶醉桌前 提交于 2019-11-30 19:35:47
问题 So I'm working on a project where there are tasks that make up a scavenger hunt. So when a user clicks on a particular hunt, I'd like the show.html.erb file to show the hunt as well as the tasks associated with that hunt. Both models (Hunt.rb and Task.rb) have "has_and_belongs_to_many" relationships with one another. My controller originally had this code, but it showed every task in the database, instead of just the tasks associated with a particular hunt. def show @hunt = Hunt.find(params[

Ebean ManyToMany query

江枫思渺然 提交于 2019-11-30 19:13:47
I have two classes, user and car. Both have ManyToMany mapping to each other. User: @Entity public class User extends Model { private int year; @ManyToMany(cascade=CascadeType.ALL) private List<Car> cars; } Car: @Entity public class Car extends Model { @ManyToMany(mappedBy = "cars", cascade=CascadeType.ALL ) private List<User> users; } Using ebean, I would like to query only those cars from year 1999 that have give user in their list. I do not want to iterate over the user's car list in Java code. I didn't find any documentation how many-to-many queries should look like. So I would something

How to prevent self (recursive) selection for FK / MTM fields in the Django Admin

旧时模样 提交于 2019-11-30 18:36:37
Given a model with ForeignKeyField (FKF) or ManyToManyField (MTMF) fields with a foreignkey to 'self' how can I prevent self (recursive) selection within the Django Admin (admin). In short, it should be possible to prevent self (recursive) selection of a model instance in the admin. This applies when editing existing instances of a model, not creating new instances. For example, take the following model for an article in a news app; class Article(models.Model): title = models.CharField(max_length=100) slug = models.SlugField() related_articles = models.ManyToManyField('self') If there are 3

How to filter django model by its objects in many-to-many field (exact match)?

我是研究僧i 提交于 2019-11-30 18:09:34
I have this model in my code: class Conversation(models.Model): participants = models.ManyToManyField(User, related_name="message_participants") and I need to filter this "Conversation" model objects by the "participants" many-to-many field. meaning: I have for example 3 User objects, so I want to retrieve the only "Conversation" objects that has this 3 Users in it's "participants" field. I tried doing this: def get_exist_conv_or_none(sender,recipients): conv = Conversation.objects.filter(participants=sender) for rec in recipients: conv = conv.filter(participants=rec) where sender is a User

How to create relationship many to many in SQLAlchemy (python, flask) for model User to itself

China☆狼群 提交于 2019-11-30 17:52:44
问题 I need to create a table called friends , it should looks like: friends: user_id friend_id I was trying to do this with tutorials from SQLALchemy, but I have not found how to make relation many-to-many for same table. Here's what I have tried: # friends table # many to many - user - user _friends = db.Table('friends', db.Column('user_id', db.Integer, db.ForeignKey('users.id')), db.Column('friend_id', db.Integer, db.ForeignKey('users.id')) ) class User(db.Model, UserMixin): # table name in

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

a 夏天 提交于 2019-11-30 16:30:12
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 generate migration diff there would be SQL statement to delete this column. Relative info App: Symfony 2.5