many-to-many

How to work with unsaved many-to-many relations in django?

怎甘沉沦 提交于 2019-12-01 05:57:57
I have a couple of models in django which are connected many-to-many. I want to create instances of these models in memory , present them to the user (via custom method-calls inside the view-templates) and if the user is satisfied, save them to the database. However, if I try to do anything on the model-instances (call rendering methods, e.g.), I get an error message that says that I have to save the instances first. The documentation says that this is because the models are in a many-to-many relationship. How do I present objects to the user and allowing him/her to save or discard them

Laravel 4 many to many relationship not working, pivot table not found

一世执手 提交于 2019-12-01 05:48:03
I'm currently having problems with a n:n relationship with Laravel 4, I'm having an error wiht pivot table which is quering on a table with with both components on singular name. I create a pivot table lands_objs and populate it: Models are: <?php class Obj extends Eloquent { protected $guarded = array(); public static $rules = array(); public $timestamps = false; public function land() { return $this->belongsToMany('Land'); } <?php class Land extends Eloquent { protected $guarded = array(); public static $rules = array(); public $timestamps = false; public function objs() { return $this-

SQLAlchemy order_by many to many relationship through association proxy

半世苍凉 提交于 2019-12-01 05:41:47
I have a many to many relationship setup in a Flask app in SQLAlchemy using a Association Object. I then have have assocation proxies setup between the the classes, to give more direct access rather than going via the association object. Here is an abbreviated example of the setup: class Person(Model): __tablename__ = 'persons' id = Column(Integer, primary_key=True) last_name = Column(Text, nullable=False) groups = association_proxy('group_memberships', 'group') # Other stuff class Group(Model): __tablename__ = 'groups' id = Column(Integer, primary_key=True) name = Column(Text, nullable=False)

Select custom columns from Laravel belongsToMany relation

巧了我就是萌 提交于 2019-12-01 05:29:19
问题 Im trying to select only specific attributes on the many-to-many relation users , just like in one-to-one. But using select() on belongsToMany() seem to be ignored and i'm still getting all the User attributes. class Computer extends Eloquent { public function users() { return $this->belongsToMany("User")->select("email"); } public function admin() { return $this->hasOne("User")->select("email"); } } Computer::with("users")->get(); Is there a way of filtering only specified columns from

How to eagerly load a many to many relationship with the entity framework code first?

雨燕双飞 提交于 2019-12-01 04:54:07
问题 I'll give the most basic example that I can think of for the purpose of clarity. Lets say that I have two entities of the following form: public class Student { public int Id {get;set} public string FullName {get;set;} public virtual ICollection<Course> Courses {get;set;} } public class Courses { public int Id {get;set;} public string FullName {get;set;} public virtual ICollection<Student> Students {get;set;} } Those two entities map to three tables, the third one being a table for the joins.

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

别说谁变了你拦得住时间么 提交于 2019-12-01 04:21:21
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 ForeignKey field. This is what I have so far: # admin.py from django.contrib import admin from myapp.models

How to access fields in a customized many-to-many through object in templates

徘徊边缘 提交于 2019-12-01 03:31:29
Consider the following models: class Person(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(Person, through='Membership') class Membership(models.Model): person = models.ForeignKey(Person) group = models.ForeignKey(Group) date_joined = models.DateField() invite_reason = models.CharField(max_length=64) Membership is a customized many-to-may through object with extra fields. If I have a person instance, how can I access the corresponding date_joined fields of all its membership relations -

Is it possible to directly reference a many-to-many table using entity framework, code first

。_饼干妹妹 提交于 2019-12-01 02:33:05
I am using the entity framework and modelling a many-to-many relationship. I have created the relationship between the two entities using the fluent API (let's say users and groups): this.HasMany(t => t.Users) .WithMany(t => t.Groups) .Map( m => { m.ToTable("GroupMembers"); m.MapLeftKey("Group_Id"); m.MapRightKey("User_Id"); }); This works great, but I'd like to also be able to reference the GroupMembers table directly. To do that, I have something like: [Table("GroupMembers")] public class GroupMember { #region Properties /// <summary> /// Gets or sets the group. /// </summary> public virtual

Doctrine Many to Many Insert

随声附和 提交于 2019-12-01 02:04:37
问题 i have some promblem. i was research and try all suggest but no one work. and i end up with : Argument 1 passed to Entity\User::addCategories() must be an instance of Entity\Category, string given, i have manytomany relationship, user, user_category, and category user <?php namespace Entity; use Doctrine\Common\Collections\ArrayCollection; use Gedmo\Mapping\Annotation as Gedmo; use Doctrine\ORM\Mapping as ORM; /** * @Entity * @Table(name="user") */ class User { /** * @Id * @Column(type=

Why does many-to-many data structure require two additional tables?

浪子不回头ぞ 提交于 2019-12-01 01:35:52
This question is based on the thread . If we have one-to-many data structure, we need to have a "help-table" to store for instance phonenumbers for one person. Many person cannot have the same phonenumbers. I look forward for an explanation why we then need two "help-tables" between many-to-many relations. An example of this is a question-site where many users can add the same tags: alt text http://files.getdropbox.com/u/175564/db/db-55.png Why do we need to have the tables Question-Tag-xref and Question-Tags ? Why cannot we just have one table for tags as follows? Question_id | tag 1 C 1 C++