foreign-key-relationship

How to pass foreign key attributes down through a nested form in Rails 3

社会主义新天地 提交于 2019-12-24 15:25:11
问题 I have three models: class Client < ActiveRecord::Base has_many :balancesheets has_many :investment_assets, :through => :balancesheets class Balancesheet < ActiveRecord::Base belongs_to :client has_many :investment_assets, :dependent => :destroy accepts_nested_attributes_for :investment_assets, :allow_destroy => true class InvestmentAsset < ActiveRecord::Base belongs_to :balancesheet belongs_to :client I have two questions that have to do with the foreign key client_id. First, when I create a

Is it possible to create a foreign key constraint using “NOT IN” logic

旧街凉风 提交于 2019-12-24 13:33:57
问题 Is it possible to add a foreign key constraint on a table which will allow values which do NOT exist in another table? In the example below, both tables contain the field USER_ID. The constraint is that a customer and and an employee cannot have the same USER_ID value. I am very limited in adding new tables or altering one of the tables in any way. CUSTOMER -------------------------- USER_ID varchar2(10) EMPLOYEE -------------------------- USER_ID varchar2(10) I thought of a few workarounds,

How to update foreign key in EF 6 - Code First

倖福魔咒の 提交于 2019-12-24 10:12:35
问题 I'm trying to update a foreign key in EF6 (Code First) in an ASP.Net MVC manner. Let me explain : My entities public class Person { public int Id { get; set; } public string Name { get; set; } public virtual Country Country { get; set; } } public class Country { public int Id { get; set; } public string Name { get; set; } } My database Table Countries with 2 records : Id = 1, Name = France Id = 2, Name = Canada Table People with 1 record : Id = 1, Name = Nicolas, Country_Id = 1 My code // In

EF6 Foreign key with one-to-one relationship and two-way property navigation

梦想与她 提交于 2019-12-24 08:07:12
问题 I cannot seem to get EF6 to generate a FK when I am using two-way navigation. Here are my classes (removed some properties for brevity): public class BaseSystem { public int Id { get; set; } public SystemConfiguration Configuration { get; set; } } public class SystemConfiguration { public int Id { get; set; } public BaseSystem System { get; set; } } I want the SystemConfiguration table to have a FK reference back to BaseSystem.Id . Here's my fluent API code: modelBuilder.Entity

EntityFramework include vs join performance

99封情书 提交于 2019-12-23 19:11:05
问题 I'd like to know, when using entity framework, which one yields better performance? I've read that if you have foreign relationships between your entites, it's preferred to use include over join. If I'm just retrieving 1 row with records from 2 different entites (with foreign key relationship), does it make a difference if I were to use include over join? Does the amount of records I'm fetching back affect the performance between join and include? 回答1: I would highly recommend you to do some

“Delete Where” cascade delete in Hibernate?

…衆ロ難τιáo~ 提交于 2019-12-23 12:09:00
问题 I am trying to cascade delete rows in a join table via one of its foreign keys and it has another table related to it that I would like to remove all rows associated with this ID as well. So it looks like the diagram below. When I use Session.delete(reqCandObject) with hibernate it works fine and cascades through deleting the One entry from the candidate_jobReq table as well as the associated comments. However, I want to delete all of the candidate_jobReq entries that have a certain candidate

Database tables, one table referencing multiple unrelated tables

让人想犯罪 __ 提交于 2019-12-23 11:59:48
问题 This question has come up a few times in various forums in my searching, but none have provided a concise resolution. If I have the following tables: User +- id +- username +- password Article +- id +- title +- content and I want to join them in order to determine who created what articles, I could simply add the column user_id to Article to use as a reference. Alternatively, I'm adding an intermediate table to show who/when/what, for example: User +- ... Article +- ... ChangeHistory +- id +-

MySQL Error creating foreign key on <ColumName> (check data types)

吃可爱长大的小学妹 提交于 2019-12-23 07:49:40
问题 I seem to be having trouble setting up a Foreign Key between two of my tables. Here is the CREATE clause for each table: CREATE TABLE IF NOT EXISTS `dbname`.`CallRecord` ( `id` INT NOT NULL AUTO_INCREMENT, `user_id` INT NOT NULL, `city_id` INT NOT NULL, `created` DATETIME NULL, `timestamp` TIMESTAMP NULL, PRIMARY KEY (`id`), INDEX `user_id_fk_idx` (`user_id` ASC), INDEX `city_id_fk_idx` (`city_id` ASC), CONSTRAINT `user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `dbname`.`User` (`id`) ON

Mysql errno 150 trying to create table with foreign key references

狂风中的少年 提交于 2019-12-22 10:48:41
问题 I'm trying to create a table in mysql with a foreign key reference, like this: In database A: CREATE TABLE replication ( id varchar(255) NOT NULL PRIMARY KEY, uid varchar(255) NOT NULL, value int(11) NOT NULL, FOREIGN KEY (uid) REFERENCES databaseB.users(username) ); In database B i have a table named users like this: +-----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+------

Maintaining a foreign key relationship when inserting into tables with autoincrementing Id's

爱⌒轻易说出口 提交于 2019-12-22 08:28:30
问题 I have two tables: Defect and DefectData. Each Defect may or may not have one or many DefectData. As such DefectData has a DefectId column as a foreign-key. The Id in both tables is an autoincrementing identity. The problem I am having is that when I want to insert a new Defect and its DefectData the Defect is inserted first and gets an Id, but I don't know what that Id is to give to DefectData. My solution is to then select from defects matching inserted data to get the Id. Insert Defect Get