foreign-keys

EF4 Independent Associations - Why avoid them?

 ̄綄美尐妖づ 提交于 2019-11-29 07:15:02
I saw this comment on MSDN ( link and link ): "Note that Independent Associations should often be avoided since things like N-Tier and concurrency becomes more difficult." I'm new to EF4 and I'm building an n-Tier web app. This sounds like an important pitfall. Can someone explain to me what this means? I think it's personal preference. Originally, EF was created to only use indep. associations and aligned with a more classic ERM approach. However, most of us devs are so dependent on FKs that it made life very complex. So MS gave us FKs in EF4 which meant not only having the FK as a property

How to keep foreign key relations consistent in a “diamond-shaped” system of relationships

不打扰是莪最后的温柔 提交于 2019-11-29 07:13:54
Consider this situation: a Car is bought from a Salesperson . A Salesperson works at a Showroom (and at only one Showroom). A Showroom is affiliated to a Manufacturer , and only sells cars made by that Manufacturer. At the same time, a Car is of a particular Model , and a Model is made by a Manufacturer. Restriction R: A Car's Model's Manufacturer must be the same Manufacturer as the Car's Salesperson's Showroom's affiliated Manufacturer. The diagram shows the obvious foreign key relationships. ----> Manufacturer <---- | | | | Showroom | ^ | | Model | ^ Salesperson | ^ | | | --------- Car ----

Foreign Keys - What do they do for me?

纵然是瞬间 提交于 2019-11-29 06:50:19
I'm building a small application and setting up foreign key relationships between tables. However I'm confused as to WHY I really need this? What is the advantage - does it assist me when writing my queries that I don't have to perform any joins? Here's an example snippet of my database: +-------------------+ | USERS | +-------------------+ | user_id | | username | | create_date | +-------------------+ +-------------------+ | PROJECTS | +-------------------+ | project_id | | creator | | name | | description | +-------------------+ There is a key relationship between users . user_id and

Accessing parent object attribute from child's object in Rails

元气小坏坏 提交于 2019-11-29 06:36:15
I have a model called Category which looks like this: class Category < ActiveRecord::Base has_many :categories belongs_to :category,:foreign_key => "parent_id" end I have a view which shows all the categories with some of their attributes. I can access category.parent_id , but I would like to be able to do something like category.parent_name . I can see myself creating a model method to fetch all categories and filling the collection with the correspondent parent name of each category, but I'm wondering if there is anyway to do this easily. EDIT: I have modified the model to have it like this:

SQL Server: how to know if any row is referencing the row to delete

随声附和 提交于 2019-11-29 06:34:10
问题 You cannot delete a row if any row is referencing the row to delete via a FK. Is it possible to know if any row is referencing the row to delete before executing a DELETE statement? 回答1: This script will show all the tables that have rows that reference the row you are trying to delete: declare @RowId int = 1 declare @TableName sysname = 'ParentTable' declare @Command varchar(max) select @Command = isnull(@Command + ' union all ', '') + 'select ''' + object_name(parent_object_id) + ''' where

sqlalchemy: create relations but without foreign key constraint in db?

邮差的信 提交于 2019-11-29 05:55:58
Since sqlalchemy.orm.relationship() already implies the relation, and I do not want to create a constraint in db. What should I do? Currently I manually remove these constraints after alembic migrations. Instead of defining "schema" level ForeignKey constraints create a custom foreign condition ; pass what columns you'd like to use as "foreign keys" and the primaryjoin to relationship . You have to manually define the primaryjoin because: By default, this value is computed based on the foreign key relationships of the parent and child tables (or association table). In [2]: class A(Base): ...:

Entity Framework relationships between different DbContext and different schemas

淺唱寂寞╮ 提交于 2019-11-29 05:44:05
So, I have two main objects, Member and Guild. One Member can own a Guild and one Guild can have multiple Members. I have the Members class in a separate DbContext and separate class library. I plan to reuse this class library in multiple projects and to help differentiate, I set the database schema to be "acc". I have tested this library extensively and can add, delete, and update Members in the acc.Members table. The Guild class is as such: public class Guild { public Guild() { Members = new List<Member>(); } public int ID { get; set; } public int MemberID { get; set; } public virtual Member

Adding constraints in phpMyAdmin

别等时光非礼了梦想. 提交于 2019-11-29 05:39:17
I feel like I'm being stupid, but I can't find anywhere on the phpMyAdmin interface to add constraints to foreign keys e.g. CASCADE ON DELETE I've looked for similar questions on here and on the phpMyAdmin wiki but I can't find anything about it. I realise I could do this via the query interface, but I'd like to know how to do it through the graphical interface. First, you should have your storage engine as InnoDB. Then select a table and go to 'Structure' tab. Under the table you will see 'Relation view', click it. From there you could add constraints. CASCADE Whenever rows in the master

Dealing with import of foreignKeys in django-import-export

 ̄綄美尐妖づ 提交于 2019-11-29 05:20:24
I don't understand how django-import-export module deals with ForeignKeys. Here is a simple exemple : models.py class TFamilies(models.Model): id_fam = models.AutoField(primary_key=True, unique=True) name_fam = models.CharField(max_length=1024, blank=True,verbose_name='Famille') class TGenus(models.Model): id_genus = models.AutoField(primary_key=True, unique=True) name_genus = models.CharField(max_length=1024,verbose_name='nom de genre') id_fam = models.ForeignKey(TFamilies, null=True, db_column='id_fam', blank=True, verbose_name='Famille') I would like to allow people adding genus with family

How to add Foreign Key (MySQL)

时间秒杀一切 提交于 2019-11-29 04:53:16
问题 I'm extremely new to SQL and I'm trying to perform a simple ALTER TABLE to create a new column and use it as a foreign key to reference another simple table in my database. I've altered both tables to be InnoDB However, when executing the ALTER TABLE code, I get the following error: Error 1452 Cannot add or update a child row: a foreign key constraint fails (`toys`.<result 2 when explaining filename '#sql-6d4_6'>, CONSTRAINT `#sql-6d4_6_ibfk_1` FOREIGN KEY (`toy_id`) REFERENCES `toys` (`toy