foreign-key-relationship

Can't save changes to child tables using LINQ to SQL that have foreign key constraints

I am trying to teach myself LINQ to SQL and have decided to do a small MVC.NET project to get my feet wet. The problem is that I have fallen very early on with the following error. I am making a golf application so I have setup the database and got my dbml classes made. The database has a course table and a hole table. The hole table re...

Saving parent/child header/line using Doctrine 1.2

I have a simple parent-child/header-line model in my project. The problem is that its creating a cyclic relation or something, and not letting me save the parent without the child! Detect relations is switched off! detect_relations: false ... BillHeader: package: Billing tableName: Bill_Headers actAs: SoftDelete: ~ columns: ...

Linq: To join or not to join (which is the better way, joins or relationships)

I have written quite a bit of code which uses the Linq2Sql table relationships provided to me just by having foreign keys on my database. But, this is proving to be a bit laborious to mock data for my unit tests. I have to manually set up any relationships in my test harness. So, I am wondering if writing Linq joins rather than relying ...

What is the preferred way to set foreign relationships for an entity?

Product product = new Product() { Category = category }; _session.CommitChanges(); vs. Product product = new Product() { Category.ID = category.ID }; _session.CommitChanges(); What is the difference? Which one to use? Both seem to be valid and get correctly saved in the database. ...

Modelbinder creates a foreign relationship unnecessary.. how to solve?

I have a Product entity that has a foreign key relationship to Manufacturer. I want to make it optional whether user adding a new product wants to set a manufacturer. In my create view I have, <%= Html.LabelFor(p => p.Manufacturer.Name) %> <%= Html.EditorFor(p => p.Manufacturer.Name) %> In create action, public ActionResult Create(P...

Rails: Non id foreign key lookup ActiveRecord

I want ActiveRecord to lookup by a non-id column from a table. Hope this is clear when I give you my code sample. class CoachClass < ActiveRecord::Base belongs_to :coach end class Coach < ActiveRecord::Base has_many :coach_classes, :foreign_key => 'user_name' end When I do a coach_obj.coach_classes, this rightly triggers SELE...

Siebel - How to get all accounts of an employee with eScript?

Hi, how can I get all accounts of am employee? In the "Siebel Object Interaces Reference" I found an example, how to get all industries of an account: var myAccountBO = TheApplication().GetBusObject("Account"); var myAccountBC = myAccountBO.GetBusComp("Account"); var myAssocBC = myAccountBC.GetMVGBusComp("Industry"); So I would like ...

Database design - ERD. Modeling Question

Hello Hopefully someone may be able to quickly advise the best way for me to model my ERD (I'm using IDEF1X & ERWin not Chen Notation) although it doesn't really matter. Basically I have Three Entities Organisation Person Trustee Business rules state that a Trustee can be either a person or organisation. My question is, would i...

T-SQL - create new foreign key relationship from non-normalized data

I am trying to figure out the best Transact-SQL to transform non-relational tables into tables that are more relational, and support foreign keys. Suppose I have a table FRUIT Id Name USState 1 Apple Washington 2 Pineapple Hawaii 3 Orange Florida 4 Peach Georgia etc I want the ...

How to change the foreign key referential action? (behavior)

When table was set up with a column that has a foreign key and is set to cascade (delete child when parent is deleted) what would the sql command to change this to be restrict? (can't delete parent if it has children) ...

How to retrieve the status of Foreign Key constraint?

I have the SQL query for getting all the constraint names, but not sure how to get its status like whether it is enabled/disabled? SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint, SCHEMA_NAME(schema_id) AS SchemaName, OBJECT_NAME(parent_object_id) AS TableName, type_desc AS ConstraintType,* FROM sys.objects Any help? ...

Doctrine Override Getters and Setters for Relation fields

Hi, Does anyone know how to override Doctrine_Record getters and setters for Relation fields. For example if I have a class Note, Note has many Users, now can I override, for example, this operation Note->Users[] = $user1 ? Thanks! ...

How to retrieve a Doctrine record with all relational records?

Hi, I was wondering if there is a way to get a record with all relational data, something like a 'Deep-Fetch' So if a model Child were related to another model Parent, can we fetch Child & then access Child->Parent->name thru a single query? Doctrine today fires a query whenever a relationship is accessed. Is this too costly? does it n...

creating models with multiple references in rails

I have a model defined as class A < ActiveRecord::Base belongs_to :b belongs_to :c end How do I create a new instance of A associated with both b and c. I've got the ids for b and c. ...

What happens to models with BelongsTo and hasOne relationship setup?

What happens when two models are associated with a belongsTo and a hasOne relationship at the same time? Does the framework detect this situation to avoid retrieving too much data? EDIT: CakePHP specifically, although what other frameworks do would be helpful, too. ...

Postgresql MATCH PARTIAL work around?

I'm trying to work around Postgresql 8.4's lack of MATCH PARTIAL. I have the following schema: [vehicles] lot_id | vin | source | year | make | model ... primary key ( lot_id, vin, source ) [pictures] picture_id | lot_id | vin | url | sha1 ... primary key ( picture_id ) Now, what I want is a compound FOREIGN KEY that REFERENCES t...

Should you design created_by and last_update_by in User table?

Sometime back while designing something that included user management, I was required to have created_by and last_updated_by columns in the User table. To me it seemed a good idea to have a 1:1 relationship on User itself as it would serve as an additional check. The obvious issue is creating the first user who will have to create himse...

How to create a relational Schema with following tables?

Hi Currently I have three tables. GrandParent( tel int, G_Counter int, GField varchar(10)); Parent( tel int, G_Counter int, P_counter int, PField Varchar(5)); Child(tel int, G_counter int, P_counter int, C_Counter int, CField Varchar(3)); These tables are all flat tables. And these tables loop itself and the loop is determined by the...

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::Base attr_accessible :title, :ur...

The nested structure of the model

Prompt please next time. Availability: - Sections of the catalog, in different levels - The result of either directory Can standard methods include walking on the structure? Example: Section 1 Section 1.1 Section 1.2 Section 1.2.1 Need a list is not all sections of the heap, but first in Section 1., We choose to see secti...