Questions tagged [foreign-key-relationship]

1

votes
1

answer
609

Views

Relationships with ASP.NET MVC

I usually use the Ruby on Rails framework but for this project I need to work with ASP.NET MVC and I'm confused. Basically I have 1 table : Page = (id, name, category_id) Category_id is actually a link to a page (a page can be linked to another page). I set up foreign keys and everything, the model...
marcgg
1

votes
1

answer
2.1k

Views

How handles JPA JOINs with available foreign key entry but not available foreign entry?

I wonder how JPA defines to handle following scenario: Table A: | Table B: ID FK_B | ID 1 10 | 10 2 null | 12 3 11 | I want all Table A entries with FK_B NULL or referencing not available Table B entry. public class A implements Serializable { @Id private Long id; @JoinColumn(name = 'FK_B...
marabol
1

votes
2

answer
145

Views

MySQL Basic about relationship

My doubt is about how to treat the follow thing: I have a system where a user belong to a company, and this user have their clients. How is the right way to get a list of all company clients and the follow user name?? In the client table where i have a field with the one of this relations: A compan...
Roberto
1

votes
1

answer
518

Views

Django: many-to-one fields and data integrity

Let's say that I have a Person who runs an inventory system. Each Person has some Cars, and each Car has a very large number of Parts (thousands, let's say). A Person, Bob, uses a Django form to create a Car. Now, Bob goes to create some Parts. It is only at the form level that Django knows that...
John
1

votes
1

answer
314

Views

Non-normalized association with legacy tables in Rails and ActiveRecord

I am building a Rails application accessing a legacy system. The data model contains Customers which can have one or more Subscriptions. A Subscription always belong to one and only one Customer. Though not needed, this association is represented through a join table 'subscribes', which do not have...
1

votes
1

answer
773

Views

has_many, belongs_to association where has_many associated model has two alias fk in belongs_to associated_model

I have a User model that has many fights. Fight belongs to User. There are two foreign keys in the fight table that reference back to the user PK -- challenger_id and challengee_id. The trick is how do I write the has_many association on the User model so that it returns fights where user_id = chal...
keruilin
1

votes
1

answer
245

Views

Relating two models and accessing them with a single controller in Rails

Background: I am playing around with the feedzirra plugin in a rails app, and I am attempting to utilize both the feed and entry accessors of the parsed feed in a single view. To accomplish this, I have created two models: feed and feed_entry. They are as follows: feed.rb: class Feed < ActiveRecord...
anxiety
1

votes
2

answer
1.9k

Views

Database schema dilemma with foreign keys pointing to multiple tables (exclusive arc)

Hopefully my description is a little better than the title, but basically I'm having an issue with one part of a new application schema and i'm stuck on what is the most manageable and elegant solution in table structure. Bare bones table structure with only relevant fields showing would be as foll...
Phil
1

votes
1

answer
1k

Views

Multiple relationships with lookup tables in Entity Framework

The context of the question is ASP.NET MVC2 / EF4. I have a number of lookup tables in the database which have previously been programmatically referenced, each from a number of other tables... So there might be a country table with country-id shortcode, desc, and half a dozen tables that have a cou...
Andiih
1

votes
2

answer
1.4k

Views

ActiveRecord relation using an array of foreign keys

Is that possible to establish a relationship between Tree and Branch such as: class Tree < ActiveRecord::Base has_many :branches end class Branch < ActiveRecord::Base belongs_to :tree end But with an array of foreign keys branch_ids stored in Tree? I know it's the opposite of the default process, bu...
moshimoshi
1

votes
1

answer
783

Views

How safe is to set relationships to delete on cascade?

I have this big database on mysql (104 tables), where almost every single table has a FK pointing to a single table, like the master table. There a huge web of relationships, and when I need to delete a record from the 'master' table, obviosly, there a lot of errors because of the relationships. All...
josecortesp
1

votes
2

answer
169

Views

Database Foreign Relations

I am working on a project that is a customized and specific CMS. In the frontend many of the fields will have pre-populated choices. However for these fields there needs to be an 'Other' option that allows for a user entered text string. The project scope does not want these new 'other' values to be...
maestrojed
1

votes
1

answer
841

Views

foreign-key relationship with Doctrine concrete inheritance

In my schema, I have a generic table Animal and an inherited table Dog. Before using doctrine, I used to implement this pattern with an inherited id referencing the generic id as foreign key. I can't reproduce the same with Doctrine, and I feel like something is missing. The schema I used to produce...
1

votes
1

answer
537

Views

referencing multiple foreign keys php mysql

I'm very new to php/MySQL and I'm having a bit of trouble. Help would be much appreciated. I have 2 tables laid out as such: table team team_id,team_name table schedule game_id,game_time,team1_id,team2_id,location schedule.team1_id and schedule.team2_id are both foreign keys to team.team_id. I'm tr...
Ben Poon
1

votes
1

answer
397

Views

many-many model join with SQLAlchemy

I'm having the worst time trying to get a many-many join to work using models in SQLAlchemy. I've found lots of examples online, but I can't ever seem to figure out if their strings represent the column names they'd like versus what the database tables actually have, or they're using Table instead...
Sarah Vessels
1

votes
2

answer
78

Views

Working with null's in MySQL database. One of three foreign keys have to be not null.

my problem is that i have to make table which will have foreign keys, and one of three foreign keys have to be NOT NULL and rest have to be NULL. Is there anything in MySQL to solve it? Michael.
Michal
1

votes
1

answer
98

Views

Manipulating Foreign Keys output in MYSQL

I have a table connected to another table through foreign key; First Table is the brand; it has a brand_id and brand_name fields Second Table is the Product Line; it has a Line_id and line_name fields Third Table is the Lines Offered; it has a id, Brand (which is a foreign key from the first table),...
PHPNewbie
1

votes
2

answer
947

Views

SQL Server merge replication causes foreign key failures

In my application, using SQL Server 2005, I'm having two tables, let's call them Table A and Table B; a foreign key constraint is defined on Table B, referencing the primary-key column in Table A, which is an auto-generated integer ID. I'm running the following simple transaction: Start transaction...
Itaypk
1

votes
2

answer
325

Views

Unable to create Foreign Key

There are two tables: Table Course with columns CourseID (PK, int, not null) and DepartmentID (PK, FK, int, not null), and Table Class with columns ClassID (PK, int, not null) and CourseID (int, not null). I try to make Class.CourseID FK to Course.CourseID but I get this message: The columns i...
Corbex
1

votes
1

answer
84

Views

Django - Adding related books to the author

Lets take the standard example class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): title = models.CharField(max_length=100) author = models.ForeignKey(Author) #... Many other fields ... On the admin interface from the Author change page, I'd like to be abl...
Pierre de LESPINAY
1

votes
1

answer
186

Views

Foreign keys to different existing entities are not being saved on update of referencing entity

I have a POCO A entity referencing a B entity, let's say b. I want A to reference a different exising B entity, let's say bb. These steps: var b = // get existing b from somewhere out-of-context var a = new A { B = b } dbcontext.Set.Attach(a.B); dbcontext.Set.Add(a); context.SaveChanges(); generate...
CRAGIN
1

votes
1

answer
237

Views

MySQL and Foreign Keys

I have a question regarding Foreign Keys in an InnoDB Table. I have 4 tables in my database: Signup: UID - Primary Key Afid Planid Industryid Affiliates: Afid - Primary Key Plans: Planid - Primary Key Industries: Industryid - Primary Key SQL I use to add the keys: CONSTRAINT `FK_signup_industries` F...
Meisam Mulla
1

votes
1

answer
597

Views

CakePHP: Tree list scaffold

I have a SQL table called Sections with the following columns Id | Name | Parent_id I had generated the code with cake bake. The problem is that if you add a new section, I cannot choose the parent category. It works only when the controller uses scaffolding. What is the problem?
Mirko Vandrák
1

votes
1

answer
302

Views

Entity framework 4.1: a very special relationship

I have in my database a table (AccessControl) that describes a sort of users 'access control list' for the informations contained in the table Customers and other tables. Example: the entity CUSTOMER is marked by the EntityId #1. If a user belongs to the department #6, he can access the records of c...
yeswest72
1

votes
1

answer
3.7k

Views

cakePhp and a foreign key : i cannot write the foreign key in the view

i've got a problem with a foreign key field : i created a categories table with MySQLWorkbench, which is linked by a 1:n relation to another table : Articles. It seems to work, because in Articles, there is a categories_id 'INT' field . I baked the whole project, everything works fine, except this f...
Paul
1

votes
2

answer
9.2k

Views

MYSQL Creating tables with foreign keys producing errors

Trying to create a few new tables with foreign keys but am getting caught up, here's the code and the error I'm receiving, I think it has something to do with my foreign key? #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right sy...
ehime
1

votes
2

answer
288

Views

FK in one to many relationship code first

In model first, when we create a one to many relationship between two entities, there will be a FK auto-created in many end, when we do in code first, do we need to add a FK property in the many end entity? Why? Thx in advance!
James
1

votes
1

answer
1.3k

Views

Mysql connect tables through foreign key, depends from field type

Mysql database question. There is system with objects(Domains). Each domain has own table. All objects has unique 16 varchar id - guid CREATE TABLE `guid` ( `guid` varchar(16) NOT NULL, `obj_type` varchar(45) NOT NULL, `obj_id` varchar(45) NOT NULL, `actived` tinyint(4) NOT NULL DEFAULT '1', PRIM...
Stepchik
1

votes
1

answer
1.1k

Views

XML XSLT transform to create relations Primary and Foreign keys

I want to create relations between parent and child elements in xml using xslt (primary keys PK and foreign keys FK). The source xml look like this: John Doe F00025 3/3/2009 D0456 comment M00025 0.01 l 3/15/2009 D4415 3/19/2009 D0176 M00015 10 ml M00006 1 m 803125 803005 Jayne Joyce F00156 3/18/2009...
user1455484
1

votes
1

answer
895

Views

One-To-One relationship with fluent api. A Hacky way?

EF 4.3.1. I have defined User and Box entities. Each box may or may not be assigned to a user. What I'd like to achieve is to have a OwnBox property in User class, and an Owner property in Box class. in Database, I have defined OwnerId foreignkey in Boxes (Boxes.OwnerId has relation with Users.UserI...
Kamyar
1

votes
4

answer
1.3k

Views

Historize sql data in Parent-Child tables

1 Map has N Images. When a the user updates the Map data I do not make an update because then I lose the old data. Thus I do an Insert into the Map table with the same auto incremented Id but a new datetime stamp. This way I want to historize all changes on a Map in the user interface. Table Map: PK...
Pascal
1

votes
1

answer
274

Views

Trouble saving related object through Wcf DataService

To start off ive created a WCF Dataservice with Entity Framework. On the client i try do the following var user = (from u in ctx.FysPosUsers where u.Username == 'test' select u).SingleOrDefault(); ForumUser forumUser = new ForumUser(); forumUser.DisplayName = 'tester'; forumUser.TagLine = 'A random...
Martin Clausen
1

votes
6

answer
1k

Views

How to determine table row causing duplicate entry error in INSERT?

As I get a lot of answers trying to help me with getting around the error: I am mostly interested in a way to do error handling and to detect the table row creating an error than getting around my actual problem which I only use to illustrate what is coded in the stored procedure. I am doing an SQL...
WolfiG
1

votes
2

answer
1.2k

Views

How to save a Foreign key from a controller class in Grails?

Am a new comer to Groovy nd Grails.I dont know how to save a foreign key into a child table. I have two domain class called Person and Telephone.I hust tried to save but it doesn't work.please help me. Person.groovy class Person { String name String password static constraints = { name(blank...
Krishna
1

votes
2

answer
4.6k

Views

Adding Foreign keys in Visual Studio Express 2012 for web

In Visual Web Developer Express 2012 there used to be an easy to use Diagram editor where one could add foreign key contraints, but that seems to be missing from the 2012 express edition unless I'm looking over it. How can I add a foreign key contraint between two tables in the express edition of Vi...
Jorre
1

votes
1

answer
89

Views

Obtain Key SQLite Android

I have two tables in which the second table has a foreign key which is defined as table 1's primary key. Under the add operation how can I reference the newly added table 1 key to use as table 2's foreign key? // Project Table columns names private static final String KEY_ID = 'id'; // Primary, int...
Jaiesh_bhai
1

votes
1

answer
1.1k

Views

Foreign key relationship in EF Code first not returning data

I'm hoping someone will be able to help me with a problem. I'm using entity framework code first but i'm struggling with a foreign key relationship. The relationship is set up like this: public class ExpScen { [Key] [DisplayName('Exposure Id')] public int ExpId { get; set; } [DisplayName('Request Id...
user1085867
1

votes
1

answer
67

Views

Foreign key solving

I'm working on creating two different tables with foreign keys on one of them. I need to relate the sender and receiver from mailbox table, to users.item1 When I try my code, I get an error of: Check the syntax for your version of MySQL Which I did, I'm running 5.5.25 The manual shows an example whi...
user1050632
1

votes
2

answer
3k

Views

1:1 relationship in SQL Server Management Studio 2012

I want to create a 1:1 relationship in SQL Server Management Studio 2012, please help me, can't find the correct way, every time I try it creates a one to many relation.
megara
1

votes
1

answer
1.1k

Views

JPA StackOverflowError when loading data in relationship tables

I'm trying to implement loading in three tables (the beginning of the problem with mapping) Products: @Entity @Table(name = 'products') public class Product implements Serializable { @Id @Column(name = 'id') private Integer id; @OneToMany(mappedBy = 'property', fetch = FetchType.LAZY) private Collec...
andrey.ladniy

View additional questions