one-to-many

Sort a doctrine's @OneToMany ArrayCollection

好久不见. 提交于 2019-12-01 06:28:17
My question is close to this one , but does not exactly fit with mine. I've this column in an entity: /** * @var ArrayCollection[SubjectTag] * * @ORM\OneToMany(targetEntity="SubjectTag", mappedBy="subject") * @Assert\Count(max = 10, maxMessage = "You can't create more than 10 tags.") * @Assert\Valid() */ protected $subjectTags; I want to dynamically order my tags by a position, defined in SubjectTag.position . Try using the doctrine2 ORM functionality for Ordering To-Many Associations like this: /** * @var ArrayCollection[SubjectTag] * * @ORM\OneToMany(targetEntity="SubjectTag", mappedBy=

EclipseLink JPA “invalid table in this context” with @OneToMany Map

我与影子孤独终老i 提交于 2019-12-01 04:08:40
I'm hoping I'm just doing something silly here... I'm trying to set up JPA annotations for a Map<String, Phone> and getting the following stack trace. Exception [EclipseLink-6069] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.QueryException Exception Description: The field [EMPLOYEE.PHONE_TYPE] in this expression has an invalid table in this context. Query: ReadAllQuery(name="phones" referenceClass=Phone ) at org.eclipse.persistence.exceptions.QueryException.invalidTableForFieldInExpression(QueryException.java:739) at org.eclipse.persistence

accepts_nested_attributes_for: What am I doing wrong

 ̄綄美尐妖づ 提交于 2019-12-01 03:43:59
问题 I try do create a one-to-many connection in rails4. However, although I don't get an error, the nested attribute is not stored. What am I doing wrong? Station-Models class Station < ActiveRecord::Base has_many :adresses accepts_nested_attributes_for :adresses end Adress-Model class Adress < ActiveRecord::Base belongs_to :station end Station-Controller class StationsController < ApplicationController def new @station = Station.new @station.adresses.build end def create @station = Station.new

Sort a doctrine's @OneToMany ArrayCollection

穿精又带淫゛_ 提交于 2019-12-01 03:34:11
问题 My question is close to this one, but does not exactly fit with mine. I've this column in an entity: /** * @var ArrayCollection[SubjectTag] * * @ORM\OneToMany(targetEntity="SubjectTag", mappedBy="subject") * @Assert\Count(max = 10, maxMessage = "You can't create more than 10 tags.") * @Assert\Valid() */ protected $subjectTags; I want to dynamically order my tags by a position, defined in SubjectTag.position . 回答1: Try using the doctrine2 ORM functionality for Ordering To-Many Associations

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++

EclipseLink JPA “invalid table in this context” with @OneToMany Map

て烟熏妆下的殇ゞ 提交于 2019-12-01 01:19:57
问题 I'm hoping I'm just doing something silly here... I'm trying to set up JPA annotations for a Map<String, Phone> and getting the following stack trace. Exception [EclipseLink-6069] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.QueryException Exception Description: The field [EMPLOYEE.PHONE_TYPE] in this expression has an invalid table in this context. Query: ReadAllQuery(name="phones" referenceClass=Phone ) at org.eclipse.persistence.exceptions

Populating an object based on a one-to-many table relationship in SQL

不想你离开。 提交于 2019-12-01 00:08:35
I have an object in C# like this: private ClassWidget { public int ID; public List<int> WidgetFavoriteNumbers; } Let's say I have two tables in SQL, one defines widget properties, and the other holds many records for a single widget, let's say the widget's favorite numbers: widgets ----------- id (int, not null) // other properties ... widget_nums ---------- widget_id (int, not null) num (int) I find myself frequently executing two SQL queries to populate this object even though I know I can join the tables to create just one query. The reason is that it seems simpler to populate the object

What is wrong in my nested SUBQUERY predicate?

时光怂恿深爱的人放手 提交于 2019-11-30 20:39:58
I have the data model you can see below, and a nested SUBQUERY predicate, but in somehow it just not works. Any idea how to correct it? I figured out, this here down is working finally: [NSPredicate predicateWithFormat:@"SUBQUERY(bs, $B, SUBQUERY($B.cs, $C, $C.ds.name != \"xxx\").@count > 0).@count > 0"]; Ok, so here is the working solution: [NSPredicate predicateWithFormat:@"SUBQUERY(bs, $B, SUBQUERY($B.cs, $C, $C.ds.name != \"xxx\").@count > 0).@count > 0"]; 来源: https://stackoverflow.com/questions/13242383/what-is-wrong-in-my-nested-subquery-predicate

One-to-many Flask | SQLAlchemy

↘锁芯ラ 提交于 2019-11-30 19:07:11
I am trying to create a one-to-many relationship using Flask and SQLAlchemy. I want the one-to-many relationship to be as so: "For any single movie, there can be multiple characters" Here it what I have so far, but it is saving in my DB as one-to-one right now. (One movie to one character, saving multiple times in DB for multiple characters) class Movie(db.Model): __tablename__ = "movies" id = db.Column('movies_id', db.Integer, primary_key=True) movie_type = db.Column('movie_type', db.Text()) def __init__(self, movie_type): self.movie_type = movie_type def __repr__(self): return '<Movie %r>' %

How to define nested Identifying Relationships Entity Framework code first

六眼飞鱼酱① 提交于 2019-11-30 15:43:16
问题 I'm using EF5 code first in a simple test application at the moment to test various functions. I have defined an 'identifying relationship' between two entities which represent a one-to-many link. Here I define a PhotoCollection that has many child Photo entities; public class PhotoCollection { public int Id { get; set; } public virtual ISet<Photo> Photos { get; private set; } public PhotoCollection() { Photos = new HashSet<Photo>(); } } public class Photo { [Key, ForeignKey("Parent"), Column