one-to-one

Django: How to define a model relationship to achieve the following?:

My app has clients that each have a single billing profile. I'm envisioning my app having a "Client" model with an attribute called "billing_profile" which would reference another model called "BillingProfile". Rather than define "BillingProfile" with a foreign key back to "Client" (ie, "client = models.ForeignKey(Client)"), I was think...

ActiveRecord has_one relationship does not return in certain cases

Given three models that are each nested in each other. If I create the top-level object and build_* the other child objects, I can retrieve all child objects through the relationships before and after save() on the original instance. However, if I try to retrieve the 2nd level nested object after find(:id) the original parent it fails. I...

Cascade issue when deleting an entity in a one-to-one relationship using Fluent NHibernate.

I have the following db tables which I have simplified for this example: Webpage Id, URLIdentifier WebpageMetaData Webpage_id Keywords Webpage_id is the primary key for the table and a foriegn key back to the webpage table. I am then using Fluent NHibernate and its automapping feature to map these to the following POCO classes: publ...

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 correctly implement the one-to-one relation. So, could you give an one-to-one mapping examp...

NHibernate unidirectional one-to-one mapping problem.

I am trying to create a Unidirectional one-to-one relationship using NHibernate. Example: An Order is given by a Customer. Customer{ID, Name, Address} OrderN{ID, Customer, OrderDate} Here, OrderN.Customer-field is intended to store Customer.ID as an FK. And this field doesn't have any unique constraint. (The OrderN-table is given su...

How to identify one-to-one (one-to-?) relationship using INFORMATION_SCHEMA or sys views in Sql Server

So here is the problem.. Using TSQL and INFORMATION_SCHEMA or sys views, how can I identify a 1:0-1 relationship, such as FK_BaseTable_InheritedTable? In a concrete example, imagine a simple DTO - FK_JoinTable_ParentTable would be rendered as a collection of JoinTable on the ParentTable object, whereas FK_BaseTable_InheritedTable woul...

One-to-one association and filtering in Linq

Hello, Let's say I have two tables (Address and Phone) in sql which have one-to-one relationship. I have created corresponding linq to sql classes and changed the association to OneToOne I want to retrieve both objects by filtering child object. e.g I have the following query which works fine: var n = db.Addresses.Where(t => t.Phone.N...

Mapping two tables 0..n in Hibernate

I have a table Users CREATE TABLE "USERS" ( "ID" NUMBER NOT NULL , "LOGINNAME" VARCHAR2 (150) NOT NULL ) and I have a second table SpecialUsers. No UserId can occur twice in the SpecialUsers table, and only a small subset of the ids of users in the Users table are contained in the SpecialUsers table. CREATE TABLE "SPECIALU...

Map table inheritance as a one-to-one relationship with NHibernate

Hi! I have a database that has a one-to-one relationship modeled between a Person and a Address (that uses person id). However, I cannot find a way to make the map using NHibernate. My table structure is the following: PersonTable PersonId PersonName PersonAge AddressTable PersonId CountryName StreetName StateName And I would l...

Ruby on Rails: Best way to tie together two models that correspond one to one

If I have two models that are guaranteed to have a one-to-one correspondence, i.e. if one is created, I will always also need the other, and if one is deleted, I will also want to get rid of the other, what's the best way to tie them together? I see that the has_one/belongs_to :dependent method takes care of the deletions, but I don't s...

How to store some of the entity's values in another table using hibernate?

Hi guys, is there a simple way to persist some of the fields in another class and table using hibernate. For example, I have a Person class with name, surname, email, address1, address2, city, country fields. I want my classes to be: public class Person { private String name; private String surname; private String email; pr...

Fluent NHibernate joined tables one-to-one

I think this is a moderately neophyte question. I've been using NHibernate/FluentNHibernate for about 6 months or so, and I think I have a fair grasp of the basics. Now I'm pushing a little bit beyond. I'm sure this is documented, but I've spent several hours now on Google, and haven't quite figured it out. I have simple class, call it...

NHibernate - I have many, but I only want one!

Hello, I have a User which can have many Emails. This is mapped through a List collection (exposed by IEnumerable Emails on the User). For each User one of the Emails will be the Primary one ("Boolean IsPrimary" property on Email). How can I get the primary Email from User without NHibernate loads every email for the User ? I have the...

Doctrine 1.2: How do i prevent a contraint from being assigned to both sides of a One-to-many relation?

Is there a way to prevent Doctrine from assigning a contraint on both sides of a one-to-one relationship? Ive tried moving the definition from one side to the other and using owning side but it still places a constraint on both tables. when I only want the parent table to have a constraint - ie. its possible for the parent to not have an...

In SQL / MySQL, are there reasons not to put one-to-one relationship in the same table?

One-to-one relationship could usually be stored in the same table. Are there reasons not to store them in the same table? ...

Optional one-to-one mapping in Hibernate

How do I create an optional one-to-one mapping in the hibernate hbm file? For example, suppose that I have a User and a last_visited_page table. The user may or may not have a last_visited page. Here is my current one-to-one mapping in the hbm file: User Class: <one-to-one name="lastVisitedPage" class="LastVisitedPage" cascade="save-up...

Nhibernate One-to-one mapping issue with child object insert error

Hi, i've being banging my head against the desk all day with the following Nhibernate problem. Each bank account has one (and only one) set of rates associated with it. The primary key of the bank account table, BankAccountID is also a foreign key and the primary key in the AccountRate table. public class BankAccount { public virtu...

NHibernate From One-To-Many to One-To-One

I am creating the security system for the software im creating and I would like to know how i can do the following in NHibernate(if at all possible) User Account Class: public class UserAccount { public virtual int UserID { get; set; } public virtual String Username { get; set; } public virtual Privilege InvoicePrivilege { ...

How do map 1-to-1 relationship in grails to just 1 table under the covers?

Let's say I have a UserAccount domain class that has a UserPreferences domain class. I do this to separate the fields for organization purposes. Is there a way to tell grails/gorm that I really want it to map these domain classes to just the user_account table under the covers? Thanks! ...

NHibernate complex one-to-one mapping

There is a table A containing common unversioned data for entities. There are also tables B,C,D with versioned data of particular entity type. All of these tables are referencing table A. The task is to add a mapping of a property of entity's type, for example, stored in table B, which would reference table A, and specify a rule how ent...