foreign-key-relationship

Kohana-v3 ORM parent relationship

Hi all, I just started with the version 3 of the Kohana Framework. I have worked a little with the $_has_many etc. Now I have the table pages. The primary key is pageID. The table has a column called parentPageID. Now I want to make a ORM model who, when accesed like this $page->parent->find() returns the page identified by parentPageI...

Foreign Key Relationship in Rails

Hi...I am a beginner in Rails and I read that the Rails enforces the foreign key relationships at the model level and also at the database level in the migration file, while creating the table. Is it really necessary and what kind of advantage does it provide ...

Show data relationship in gridview with dropdownlist or similar?

I have data coming from two tables with a foreign key relationship - one User table containing users of the web application, and one Page table containing details about pages visited by each user. I would like to be able to view these data in a gridview or the like on a page. It's easy enough to just show the User table data like so (I'...

doctrine findby relation

I'm having trouble selecting a subset of data with doctrine. I have 3 tables Location Contact Contact_location The contact and location tables hold a name and an id the other table holds only ID's. For instance: Location loc_id: 1 name: detroit Contact contact_id: 1 name: Mike Contact_location loc_id: 1 contact_id: 1 In doctr...

SQL - Two foreign keys that have a dependency between them

The current structure is as follows: Table RowType: RowTypeID Table RowSubType: RowSubTypeID FK_RowTypeID Table ColumnDef: FK_RowTypeID FK_RowSubTypeID (nullable) In short, I'm mapping column definitions to rows. In some cases, those rows have subtype(s), which will have column definitions sp...

Rails Nested Attributes, Relationship for Shared or Common Object

This has to be a common problem, so I'm surprised that Google didn't turn up more answers. I'm working on a rails app that has several different kinds of entities, those entities by need a relation to a different entity. For example: Address: a Model that stores the details of a street address (this is my shared entity) PersonContac...

Foreign key relationships in Entity Framework v.1

I need to be to create an entity data model in the EF version 1, because my web host doesn't have Framework 4.0 yet. Below is just a simple example to show the problem. I have 3 tables, one Users table, another Webpages table, and one table with Visits. The former two tables each have a one-to-many relationship with the Visits table (w...

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 an id column: Column | Type...

Database schema question

I am designing a data model for a local city page, more like requirements for it. So 4 tables: Country, State, City, neighbourhood. Real life relationships is: Country owns multiple State which owns multiple cities which ows multiple neighbourhoods. In the data model: Do we link these with FK the same way or link each with each? Like ...

Multiple has_manys of the same model

I have these models: Person has_many :messages_form_person, :foreign_key => :from_user_id, :class_name => :messages has_many :messages_to_person, :foreign_key => :to_user_id, :class_name => :messages Message belongs_to :to_person, :foreign_key => :to_user_id, :class_name => :person belongs_to :from_person, :foreign_key => ...

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 = challenger_id or challengee_id? ...

Issues with adding FK relations via Doctrine Build Task

I've double-checked my schema, and its correct... infact doctrine also built it once.. and now its troubling me with some FK relations... I have checked for the data-types as well. All are int(4) or int(2) 2 Qs here: 1. is there an upper limit to the no of relations (dependencies/FKs) a table can have? I have upto 7 FKs in a tables 2. i...

Fluent Nhibernate - Specify foreign key constraint name between class and joined subclass

Hi, I think this should be simple, but I can't figure out how to do it. Suppose I have the following maps: public class AnimalMap : ClassMap<Animal> { Id( x => x.Id); } public class CatMap: SubclassMap<Cat> { Extends<AnimalMap>(); Map(x => x.IsDomestic); } Which creates tables as I expect: Animal ------ Id Cat ---- Animal...

How to find all foreign keys?

I'd like to find all referencing tables in my db that have a foreign key that points to a specific referenced table. Is there a query that I can run to do this? Not sure if the question is confusing. Let me know if it is and I can try to explain it in more detail. ...

creating relationships with sql server 08 express in visual web dev 2010

OK so I have never ever touched asp.net and have absolutly no idea what I am doing. I create database structures via SQL Scripts not GUI enviornments. So I am trying to learn ASP.NET and I have started an MVC Web App project. I have an account table and an address table and an account_addresses_xref table. table: account fields: acco...

Adding new fields vs creating separate table

I am working on a project where there are several types of users (students and teachers). Currently to store the user's information, two tables are used. The users table stores the information that all users have in common. The teachers table stores information that only teachers have with a foreign key relating it to the users table. u...

Foreign key referencing a 2 columns primary key in SQL Server

This question is pretty much similar to this one, but for SQL Server 2005 : I have 2 tables in my database: --'#' denotes the primary key [Libraries] #ID #Application Name 1 MyApp Title 1 2 MyApp Title 2 [Content] #ID Application LibraryID Content 10 MyApp 1 xxx 11 MyApp 1 ...

The property 'Id' is part of the object's key information and cannot be modified

Hi all, i'm using Entity Framework 4.0 and having a silly problem that i can't figure out. I have two tables: Contact: Id (primary key), Value, ContactTypeId (foreign key to ContactType) ContactType: Id (Primary key), Type (Home, Cell, Work, etc.) Entity Framework created the following two entities: Contact: Id, Value, ContactType...

Rollback in Entity Framework 4.0

Hi gurus, i have a Customer class which includes a Contact class that stores all the contacts for that particular customer, so they are linked with a foreign key relationship. Here is my scenario: the user Edits the customer's info including the contacts, and then decides to hit the "Cancel" button. The contacts are bound to a grid so ...

Database: how to share data between schema's?

Suppose I would like to have a common table for two schema's, is that possible? A table has it's schema in it's fully qualified name, e.g. [dev].[product] so it looks like this is not possible. How could I make the data in table [common].[types] (and not a copy) available to schema [dev]? A view perhaps? One more question: how about r...