many-to-many

Inserting object with ManyToMany in Django

匆匆过客 提交于 2019-12-11 11:54:14
问题 I have a blog-like application with stories and categories: class Category(models.Model): ... class Story(models.Model): categories = models.ManyToManyField(Category) ... Now I know that when you save a new instance of a model with a many-to-many field, problems come up because the object is not yet in the database. This problem usually manifests itself on form submission, which can be neatly worked around with story_form.save(commit=False) . What about a situation where there are no forms to

Entity Framework Code 1st - Mapping many-to-many with extra info

那年仲夏 提交于 2019-12-11 11:22:41
问题 I've looked through several of the questions here and am not quite connecting all the (mental) dots on this. I would appreciate some help. My Models (code first): public class cgArmorial { [Key] [Display(Name = "Armorial ID")] public Guid ArmorialID { get; set; } [Display(Name = "User ID")] public Guid UserId { get; set; } public string Name { get; set; } public string DeviceUrl { get; set; } public string Blazon { get; set; } public virtual ICollection<cgArmorialAward> ArmorialAwards { get;

Doctrine2 ManyToMany-relation doesn't save

拟墨画扇 提交于 2019-12-11 11:09:44
问题 I have a problem with my ManyToMany relation in doctrine2. The relation doesn't persist even though the relation exists. If i check afther the persist in two foreach loops the correct objects are returned. The first class is Document. class Document extends BaseEntity { .... /** * @ORM\ManyToMany(targetEntity="Job", mappedBy="documents", cascade={"all"}) * @ORM\JoinTable(name="job_document") */ protected $jobs; .... The second class is Job class Job extends BaseEntity { .... /** * @ORM

Django REST Framework: Add field from related object to ModelSerializer

拟墨画扇 提交于 2019-12-11 11:09:10
问题 I'm trying to allow a field that belongs to a related object to be readable and writable from a ModelSerializer. I have a model Group : class Group(models.Model): ... name = models.CharField(max_length=128) def get_language(self): line = self.line_set.all()[0] return line.language ... and corresponding serializer: class GroupSerializer(serializers.ModelSerializer): language = serializers.CharField(source='get_language') class Meta: model = Group fields = ('id', 'name', 'language') lookup

Design of DB table with many rows and many columns with binary information

心已入冬 提交于 2019-12-11 11:05:21
问题 We want to create a table in a sql database with ~10^6 rows. Every entry has many binary properties (say about 30, every row only has a few properties set True , and most set False ) and a few integral properties (say about 5). How do I set up such a table? Specifically, should I just have one column in the table for each property (binary or integral) or should I make columns for the integral properties and new table with the binary properties together with a many-to-many relationship? Or is

Many to Many relationship with cfwheels without composite keys

試著忘記壹切 提交于 2019-12-11 10:37:00
问题 I've been following the information from here: cfwheels.org/docs/1-1/chapter/nested-properties I've ended up downloading a sample application which breaks down at the same place code executes fine, in the sense that I get no errors, but the many-many table does not get the new entries, and when I add the entries manually in the database, they are not reflected with the checkboxes and sometimes they are removed when the model is updated. EDIT I found out the issue... just not how to solve it.

Creating a Many-to-many relationship in Laravel with additional data

孤者浪人 提交于 2019-12-11 10:18:05
问题 I have in my database a pivot table that stores extra information. It has 2 foreign keys, and an additional field. Here's what it looks like: EventTeam int event_id (fk) int team_id (fk) boolean home The intent here is that an Event may have many teams (in fact, it must have at least 2, but that's not a database constraint), and a team may participate in many events. However, for each event-team relationship, I want to also track whether the team is considered the home team for that event.

Problems with Laravel Many to Many Polymorphic Relationships

♀尐吖头ヾ 提交于 2019-12-11 09:38:15
问题 Really I need exactly what is in the Eloquent documentation. I need a tag system, with a polymorphic many to many relationship with users, posts, etc. The documentation doesn't seem to clearly state how to insert or update records with this relationship though... my attempts to do things like this: $user->tags()->save($tag); or $tag->users()->attach(Input::get('userID')); (which the above results in this error) {"error":{"type":"Illuminate\\Database\\QueryException","message":"SQLSTATE[23000]

org.hibernate.TypeMismatchException: left and right hand sides of a binary logic operator were incompatibile

孤人 提交于 2019-12-11 09:32:52
问题 I have a many-to-many relationship in JPA 2.0 provided by Hibernate 4.2.0 CR1 (recently upgraded to Hibernate 4.2.7 final) between Product and Colour as follows. The Product entity class: public class Product implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "prod_id") private Long prodId; @JoinTable(name = "prod_colour", joinColumns = { @JoinColumn(name = "prod_id",

Issue with many-to-many relationship + TPH inhertitance in Entity Framework 6

坚强是说给别人听的谎言 提交于 2019-12-11 09:09:29
问题 I am running into an issue with EF6, though I'm fairly sure that this applies to previous versions that support this type of mapping. I fear I know the answer to the question at hand, but I hope that I am doing something wrong, or there is a better workaround than what I present here. All classes are gutted for clarity. So I have public abstract class SoftwareFirmware { public long Id { get; private set; } public ICollection<DeviceType> DeviceTypes { get; private set; } public