Questions tagged [one-to-one]

Refers to the quantity of an entity as a relationship to another entity. Meaning that for every instance of an entity, there is a single related instance of another entity.

Refers to the quantity of an entity as a relationship to another entity.

Meaning that for every instance of an entity, there is a single related instance of another entity.

1496 questions
32
votes
2 answers

ModelForm with OneToOneField in Django

I have two models in Django that are related with a OneToOneField (PrinterProfile and PrinterAdress). I am trying to do a form with PrinterProfileForm, but for some reason it does NOT pass the PrinterAddress fields into the form (it's not rendered…
jhagege
  • 1,486
  • 3
  • 22
  • 36
30
votes
2 answers

Generic one-to-one relation in Django

I need to set up one-to-one relation which must also be generic. May be you can advice me a better design. So far I came up to the following models class Event(models.Model): # skip event related fields... content_type =…
Andrei
  • 10,918
  • 12
  • 76
  • 110
29
votes
1 answer

EF Code First - 1-to-1 Optional Relationship

I want to map an optional 1-to-1 relationship in an existing database with EF Code First. Simple schema: User Username ContactID Contact ID Name Obviously ContactID joins to Contact.ID. The ContactID field is nullable so the relationship is…
Chris Moschini
  • 36,764
  • 19
  • 160
  • 190
27
votes
5 answers

Symfony2 Doctrine2 trouble with optional one to one relation

I have a problem with Doctrine2 in Symfony2 and two relationed entities. There is a user-entity that can (not must) have a usermeta-entity referenced which contains information like biography etc. The usermeta is optional because user is imported by…
daluq
  • 293
  • 1
  • 4
  • 7
26
votes
5 answers

Hibernate: @ManyToOne(fetch = FetchType.LAZY) does not work on non-primary key referenced column

I have 2 tables: Order [OrderId(PK), OrderShipmentCode, ...] and Shipment[ShipmentId(PK), ShipmentCode, ...]. In Order class, I declared shipment field as follows: @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "OrderShipmentCode",…
Nghia Le
  • 535
  • 2
  • 6
  • 16
26
votes
2 answers

Java: Hibernate @OneToOne mapping

I'm trying to get Hibernate @OneToOne annotations working and not having much success here... Let's say I've got a table called status that looks like this: +------------------------------------------------+ | status …
Shaun Scovil
  • 3,905
  • 5
  • 39
  • 58
26
votes
1 answer

Deciding on foreign key while implementing one to one relationship in MySQL

I have two simple tables "items" and "orders". For the sake of simplicity lets assume that one item can only be in one order or one order can only contain one item. Now as this can be implemented using simple one to one relationship I can do…
Jay Bhatt
  • 5,601
  • 5
  • 40
  • 62
25
votes
4 answers

Fluent NHibernate & one-to-one

For a (very) long time I've been looking for an example on how to correctly implement a one-to-one mapping with Fluent NHibernate. Most resources I find say: I think you mean a many-to-one However no one actually gives an example on how to…
Bruno Reis
  • 37,201
  • 11
  • 119
  • 156
23
votes
3 answers

Django OneToOneField - in which model should I put it?

Let's assume that we have the following models. class A(Model): pass class B(Model): pass Then there is no difference between: In model A: b = OneToOneField(B, related_name=A.__name__) and in model B: a = OneToOneField(A,…
aemdy
  • 3,702
  • 6
  • 34
  • 49
21
votes
2 answers

django difference between - one to one, many to one and many to many

So, this is my first time learning computer language. And I chose python and django. Now, I got many of the basic concepts of python and also django. I can create new page with the views and all other stuff. But I am still confused with the…
Aamu
  • 3,431
  • 7
  • 39
  • 61
20
votes
2 answers

Why @OneToOne is allowing duplicate associations?

I have User and Address classes as follows: class User { ... ... @OneToOne( cascade=CascadeType.ALL) @JoinColumn(name="addr_id") private Address address; } class Address { ... ... @OneToOne(mappedBy="address") private…
K. Siva Prasad Reddy
  • 11,786
  • 12
  • 68
  • 95
20
votes
1 answer

Golang Gorm one-to-many with has-one

I'm trying to learn Go and Gorm by building a little prototype order management app. The database is MySQL. With simple queries Gorm has been stellar. However, when trying to obtain a result set involving a combination one-to-many with a has-one…
Michael Babcock
  • 703
  • 2
  • 7
  • 13
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
19
votes
2 answers

Really simple CoreData relationship but returns nil and null?

This bug has been busting me for the past 4 hours. Also when I swap it round and get the User data first then Message data... the User.name will show, but the Message.message will not. So the data is definitely going in but the relationship between…
louisinhongkong
  • 551
  • 1
  • 6
  • 13
18
votes
1 answer

Django OneToOneField with possible blank field

Working with Django 1.11 and a postgreSQL Database (just switched from sqlite and didn't have this problem before) So I have 3 models: models.py class Person(models.Model): is_parent = models.BooleanField() class…
Just trying
  • 484
  • 1
  • 5
  • 15