foreign-key-relationship

Can you explain what's association relation in database?

I thought it was alias for simple foreign key relation,but seems not. Can you take MySQL as an example what is association relation? I guess it means many2many relation,is that true? ...

Database doubly connected relationship inserting problem

I have two tables Plants and Information. For every plant there are many information, but for each plant there is a single MainInformation. So there is a one-to-many relationship and a one-to-one relationship between the two. The Information table has a PlantID and the Plants table has a MainInformationID. I want both fields in both tabl...

how do I get foreign_key to work in this simple has_many, belongs_to relationship?

I'm pulling data from Harvest. Here are my two models and schema: # schema create_table "clients", :force => true do |t| t.string "name" t.integer "harvest_id" end create_table "projects", :force => true do |t| t.string "name" t.integer "client_id" t.integer "harvest_id" end # Client.rb has_many :projects, :for...

Importing data and keeping ids and relationships

I am working on cleaning up a mess that another programmer started. The created 2 identical databases for different locations but that obviously caused major issues. They are using cakePHP and there are quite a few relationships. I am pretty sure I will have to write a script to import that data from on DB to the other and keep all th...

NHibernate Legacy Database Mappings Impossible?

I'm hoping someone can help me with mapping a legacy database. The problem I'm describing here has plagued others, yet I was unable to find a real good solution around the web. DISCLAIMER: this is a legacy DB. I have no control over the composite keys. They suck and can't be changed no matter much you tell me they suck. I can't add ...

Ruby on Rails one-to-many relationship

I would like to model a betting system relationship using the power of Rails. So let's start with doing something very simple modelling the relationship from a user to a bet. I would like to have a model Bet with two primary keys. Here are my migrations: class CreateBets < ActiveRecord::Migration def self.up create_table :bets do...

Creating nullable association with Linq2Sql

I have a nullable foreign key in a database table. I want to create a relationship in Linq2Sql, but it doesn't allow me to create an association with a nullable foreign key and if i change the nullable value to FALSE within Linq2Sql the query crashes when a null is found. This should be creating a null child object, which should be fine....

MySQL - Find entries that refer to a specified index.

Hi, So I have a booking system where I have a 'lesson_type' table with 'lesson_type_id' as PK. I have a constraint in place here so I can't delete a lesson_type if there are bookings made for that lesson_type. I would like to be able to determine if this lesson_type_id is being referred to by any entries in the bookings table (or any ...

Does Rails need database-level constraints?

I have the same problem as in the following post. So I am wondering, why doesn't Rails support generating foreign keys by default? Isn't it necessary? Or are we supposed to do it manually? ...

Django foreign keys cascade deleting and "related_name" parameter (bug?)

In this topic I found a good way to prevent cascade deleting of relating objects, when it's not neccessary. class Factures(models.Model): idFacture = models.IntegerField(primary_key=True) idLettrage = models.ForeignKey('Lettrage', db_column='idLettrage', null=True, blank=True) class Paiements(models.Model): idPaiement = mod...

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...

Problems getting foreign keys working in MySQL

I've been trying to get a delete to cascade and it just doesn't seem to work. I'm sure I am missing something obvious, can anyone help me find it? I would expect a delete on the 'articles' table to trigger a delete on the corresponding rows in the 'article_section_lt' table. CREATE TABLE articles ( id INTEGER UNSIGNED PRIMARY KEY...

Doctrine: How to traverse from an entity to another 'linked' entity?

I'm loading 3 different tables using a cross-join in Doctrine_RawSql. This brings me back the following object: User -> User class (doctrine base class) Settings -> DoctrineCollection of Setting User_Settings -> DoctrineCollection of User_Setting The object above is the result of a many-to-many relationship b...

Symfony 1.4: use relations in fixtures with propel

Hello, I just started to use the PHP symfony framework. Currently I'm trying to create fixture files in YAML to easily insert data into my MySQL database. Now my database has a couple of relations, I have the tables Organisation and Location. Organisation org_id (PK) org_name Location loc_id (PK) org_id (FK) loc_name Now I'm ...

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 the Parts belong to some specific Car,...

mysql Delete and Database Relationships

If I'm trying to delete multiple rows from a table and one of those rows can't be deleted because of a database relationship, what will happen? Will the rows that aren't constrained by a relationship still be deleted? Or will the entire delete fail? Thanks, Colin ...

Which Table Should be Master and Child in Database Design

I am quickly learning the ins and outs of database design (something that, as of a week ago, was new to me), but I am running across some questions that don't seem immediately obvious, so I was hoping to get some clarification. The question I have right is about foreign keys. As part of my design, I have a Company table. Originally, I...

How do I specify a null relation in SQLAlchemy?

Not sure what the correct title for this question should be. I have the following schema: Matters have a one-many relationship to WorkItems. WorkItems have a one-one (or one-zero) relationship to LineItems. I am trying to create the following relation between Matters and WorkItems Matter.unbilled_work_items = orm.relation(WorkItem, ...

How to test if a doctrine records has any relations that are used

Hi, I'm using a doctrine table that has several optional relations (of types Doctrine_Relation_Association and Doctrine_Relation_ForeignKey) with other tables. How can I test if a record from that table has connections with records from the related table. Here is an example to make my question more clear. Assume that you have a User an...

Composite foreign key in Doctrine

Hi, I'm not really sure I'm using the good terms, so I'll try to explain my problem first. I have a cross-reference table, CompetenceCollab, containing the associations between people and their competences. This table has two primary keys, the people's id, and the competence's id. To this point, everything is ok. However, the new feat...