Questions tagged [one-to-many]

one-to-many is relationship between two different object properties.

One object property is relating with many properties of other object. Or you can say one object relating to many objects.

In sql, a one-to-many relationship, each row in the related to table can be related to many rows in the relating table.

http://en.wikipedia.org/wiki/One-to-many

3715 questions
19
votes
1 answer

CoreData optional to-many relationships can never be nil?

Quirk I just discovered, and wanted to confirm with anyone here whether or not this is avoidable. Basically, if I have a very simple two entity model: With a to-many relationship between Entity1 and Entity2. The relationship is optional, with…
19
votes
1 answer

Creating PostgreSQL tables + relationships - PROBLEMS with relationships - ONE TO ONE

So I am supposed to create this schema + relationships exactly the way this ERD depicts it. Here I only show the tables that I am having problems with: So I am trying to make it one to one but for some reason, no matter what I change, I get one to…
Georgi Angelov
  • 4,338
  • 12
  • 67
  • 96
18
votes
1 answer

CoreData - one-to-many modeled relationship comes out as one-to-one

I am new to Core Data modeling, and I am having a hard time understanding how one-to-many relationships work. I have a parent entity called Task, which can have several instances of Comment entity. I modeled it like this: on Comments, a…
tutiplain
  • 1,427
  • 4
  • 19
  • 37
18
votes
4 answers

@OneToMany mapping list size limit

Is there any way to limit the list's size of the @OneToMany relationship in JPA? Here's my code sample: @OneToMany(mappedBy = "publication", cascade=CascadeType.PERSIST) private List commentList; I'm using EclipseLink 2.3 JPA…
gus
  • 181
  • 1
  • 1
  • 4
18
votes
3 answers

NHibernate configuration for uni-directional one-to-many relation

I'm trying to set up a relationship as follows. Each Master item has one or more Detail items: public class Detail { public virtual Guid DetailId { get; set; } public virtual string Name { get; set; } } public class Master { public…
gregmac
  • 24,276
  • 10
  • 87
  • 118
18
votes
4 answers

Add one to many in form - Backpack laravel

I'm using Backpack for Laravel to provide the backend area of my laravel website. I'm having the following tables in my database structure: This is to add sets to a match, and add matches to a tournament. These are my Models: Tournament…
nielsv
  • 6,540
  • 35
  • 111
  • 215
18
votes
2 answers

How to serialize a one to many relation in django-rest using Model serializer?

These are my models and serializers. I want a representation of Question Model along with a list of people the question was asked to. I am trying this: @api_view(['GET', 'PATCH']) def questions_by_id(request,user,pk): question =…
17
votes
3 answers

JPA Composite key with ManyToOne getting org.hibernate.PropertyAccessException: could not set a field value by reflection setter of

I have a composite key ContractServiceLocationPK made out of three id's (contractId, locationId, serviceId) of type long in an embeddable class. The class which uses this composite key, ContractServiceLocation, maps these ids, using @MapsId…
MrPlow
  • 1,295
  • 3
  • 26
  • 45
16
votes
2 answers

How do I handle table relationships with the repository pattern?

I'm implementing the repository pattern as part of an ASP.NET MVC site. Most examples I've seen of repositories are fairly simple. For example here's a typical abstract repository interface. public interface IRepository { …
16
votes
1 answer

model self-dependency (one-to-many field) implementation

I would like to implement a model with self-dependency. Say instance People_A may depend on People_B and People_C. I first implement this model with many to many key. class People(models.Model): dependency = models. ManyToManyField ('self',…
user2354910
  • 163
  • 1
  • 5
16
votes
2 answers

Database design for comments and replies

I want to create two tables one with comments and another with replies, with a one to many relationship between them. But what if they can also reply to replies, how should it be changed then? This is what I have for the one to many, but I don't…
grasshopper
  • 1,381
  • 4
  • 19
  • 36
16
votes
3 answers

Join one to many and retrieve single result

I have two tables, in PostgreSQL if that matters, with one to many relations. I need to join them so that for each "one" I only get single result from the "many" table. Not only that but I need to single out specific results from the "many"…
thorgilsv
  • 323
  • 1
  • 3
  • 11
16
votes
3 answers

Most Efficient One-To-Many Relationships in Google App Engine Datastore?

Sorry if this question is too simple; I'm only entering 9th grade. I'm trying to learn about NoSQL database design. I want to design a Google Datastore model that minimizes the number of read/writes. Here is a toy example for a blog post and…
15
votes
1 answer

count relations inside loop in twig

I use Symfony2 and twig templating. Think of the Q&A exact same as stackoverflow. There are list of questions with the count of score, answers, views and so on. How to count the answers of the qeustions inside loop in twig? There are OneToMany…
seferov
  • 4,111
  • 3
  • 37
  • 75
14
votes
1 answer

Enable cascading deletes in EF Code First without exposing foreign key

When performing a delete of a one-many relationship without exposing the foreign key, EF deletes the parent record and tries to null the foreign key on the child records. This of course causes an error because the foreign key is not nullable. Adding…
Craig M
  • 5,598
  • 4
  • 32
  • 43