one-to-one

Check if OneToOneField is None in Django

时光毁灭记忆、已成空白 提交于 2019-12-02 15:01:16
I have two models like this: class Type1Profile(models.Model): user = models.OneToOneField(User, unique=True) ... class Type2Profile(models.Model): user = models.OneToOneField(User, unique=True) ... I need to do something if the user has Type1 or Type2 profile: if request.user.type1profile != None: # do something elif request.user.type2profile != None: # do something else else: # do something else But, for users that don't have either type1 or type2 profiles, executing code like that produces the following error: Type1Profile matching query does not exist. How can I check the type of profile a

EF5 one-to-one without navigation

て烟熏妆下的殇ゞ 提交于 2019-12-02 14:53:11
问题 I'm trying to do a one-to-one relationship, with the navigation property just on one side (MVC4, EF5, code first). public class User { public int UserId { get; set; } //PK public int RankId { get; set; } //FK public virtual Rank { get; set; } //Navigation } public class Rank { public int RankId { get; set; } } Configuration: public class RankConfiguration : EntityTypeConfiguration<Rank> { public RankConfiguration() { HasKey(e => e.RankId); Property(e => e.RankId) .HasDatabaseGeneratedOption

EF5 one-to-one without navigation

你。 提交于 2019-12-02 12:04:47
I'm trying to do a one-to-one relationship, with the navigation property just on one side (MVC4, EF5, code first). public class User { public int UserId { get; set; } //PK public int RankId { get; set; } //FK public virtual Rank { get; set; } //Navigation } public class Rank { public int RankId { get; set; } } Configuration: public class RankConfiguration : EntityTypeConfiguration<Rank> { public RankConfiguration() { HasKey(e => e.RankId); Property(e => e.RankId) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); } } public class UserConfiguration : EntityTypeConfiguration<User> {

Hibernate Criteria Return parent record that have one-to-one child record not null?

北城余情 提交于 2019-12-02 07:49:57
I have a one-to-one relation like this The Parent @JsonAutoDetect @Entity @Table(name = "Parent") public class Parent{ private Integer id; private Child child; @Id @GeneratedValue(strategy= GenerationType.AUTO) @Column (name="idparent") public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent") @JoinColumn(name="idchild", nullable=true) public Child getChild() { return child; } public void setChild(Child child) { child.setParent(this); this.child = child; } } and the child

Referential integrity with One to One using hibernate

こ雲淡風輕ζ 提交于 2019-12-01 20:51:43
I'm having two tables - Foo { foo_id, name } Foo_properties { fp_id, foo_id, phoneNumber} Now I want to map this in my object model using hibernate.. I need a foo_id in Foo_properties because i want to maintain referential integrity and want to add ON DELETE CASCADE constraint. so I mapped the relation in the following way - @Entity public class Foo{ @Id private long foo_id; private String name; @OneToOne(mappedBy = "foo") private FooProperties fooProperties; } @Entity public class FooProperties{ @Id private long fp_id; private String phoneNumber; @OneToOne @JoinColumn(name = "foo_id",

NHibernate one-to-one mapping where second table data can be null

扶醉桌前 提交于 2019-12-01 03:26:29
I have an existing database with the table Transactions in it. I have added a new table called TransactionSequence where each transaction will ultimately have only one record. We are using the sequence table to count transactions for a given account. I have mapped this as a one-to-one mapping where TransactionSequence has a primary key of TransactionId. The constraint is that there is an instead of trigger on the transaction table does not allow updates of cancelled or posted transactions. So, when the sequence is calculated and the transaction is saved, NHibernate tries to send an update on

Generic one-to-one relation in Django

≯℡__Kan透↙ 提交于 2019-12-01 02:14:24
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 = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') class Meta: unique_together = ('content_type', 'object_id') class Action1(models.Model): # skip action1 related fields... events = generic.GenericRelation(Event, content_type_field='content_type', object_id_field='object_id')

Hibernate one-to-one mapping with a reference column (XML mapping)

陌路散爱 提交于 2019-12-01 00:08:29
I have a user table and a user_detail table with one to one mapping user_detail table have a field user_id to be used for this relation which stores id field value of corresponding user. How to write the hibernate hbm file for this relation? UPDATE what my problem is that user's primary key is id , user_detail's foreign key is user_id all the examples i got in internet users user_id as users primary key and the same as foreign key in other table For User mapping.... <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate

How to delete Child or Parent objects from Relationship?

强颜欢笑 提交于 2019-12-01 00:03:28
I did a small application with more relationships. Now I want to delete details of my table how can I delete I don't get any Idea to delete. Relationships are like below: PanCard-->Employee (Ono To One) Employee-->ProjectManger (bi-directional many-to-one association to Employee) Projects -->ProjectManager(bi-directional many-to-one association to Projects) Now I want delete the data of one by one table data Below is my POJO classes Code: PanCard.java @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="id") private int id; @Column(name="pName") private String pName; @Column

How to delete Child or Parent objects from Relationship?

六月ゝ 毕业季﹏ 提交于 2019-11-30 18:58:01
问题 I did a small application with more relationships. Now I want to delete details of my table how can I delete I don't get any Idea to delete. Relationships are like below: PanCard-->Employee (Ono To One) Employee-->ProjectManger (bi-directional many-to-one association to Employee) Projects -->ProjectManager(bi-directional many-to-one association to Projects) Now I want delete the data of one by one table data Below is my POJO classes Code: PanCard.java @Id @GeneratedValue(strategy