AnantLabs / codesmith

Automatically exported from code.google.com/p/codesmith
1 stars 0 forks source link

Associations not generated when PK columns have same name on different tables #532

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Associations don't get generated when PK columns have the same name in 2 tables 
with a relationship between them. Something (SchemaExplorer?) doesn't like this 
and the associations are not created by the Codesmith NHibernateHelper code.

I created a simple test schema, comprising 4 tables, model, model_cell, model2 
and model_cell2:

- model_cell has PK column "cell_id" and has an FK column "model_id" 
referencing model's PK column "model_id".

- model_cell2 has PK column "id" and has an FK column "model_id" referencing 
model's PK column "id" (i.e. both model2 and model_cell2 have PK columns with 
the same name).

When I run Codesmith, I get associations generated for the model  to model_cell 
relationships, but not for model2 to model_cell2 relationships.

SQL (Postgres 9) to generate a schema to reproduce this issue is as follows:

-- Create tables section -------------------------------------------------

-- Table model

CREATE TABLE "model"(

"model_id" Serial,

"model_name" Character(20)

)

WITH (OIDS=FALSE);

-- Add keys for table model

ALTER TABLE "model" ADD CONSTRAINT "Key1" PRIMARY KEY ("model_id");

-- Table model_cell

CREATE TABLE "model_cell"(

"cell_id" Serial NOT NULL,

"cell_name" Character(20),

"model_id" Integer

)

WITH (OIDS=FALSE);

-- Add keys for table model_cell

ALTER TABLE "model_cell" ADD CONSTRAINT "Key2" PRIMARY KEY ("cell_id");

-- Table model2

CREATE TABLE "model2"(

"id" Serial NOT NULL,

"name" Character(20)

)

WITH (OIDS=FALSE);

-- Add keys for table model2

ALTER TABLE "model2" ADD CONSTRAINT "Key3" PRIMARY KEY ("id");

-- Table model_cell2

CREATE TABLE "model_cell2"(

"id" Serial NOT NULL,

"name" Character(20),

"model_id" Integer

)

WITH (OIDS=FALSE);

-- Add keys for table model_cell2

ALTER TABLE "model_cell2" ADD CONSTRAINT "Key4" PRIMARY KEY ("id");

-- Create relationships section 
------------------------------------------------- 

ALTER TABLE "model_cell" ADD CONSTRAINT "model_has_cells" FOREIGN KEY 
("model_id") REFERENCES "model" ("model_id") ON DELETE NO ACTION ON UPDATE NO 
ACTION;

ALTER TABLE "model_cell2" ADD CONSTRAINT "model2_has_cells2" FOREIGN KEY 
("model_id") REFERENCES "model2" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

What is the expected output? What do you see instead?

When I run Codesmith, I get associations generated for the model  to model_cell 
relationships, but not for model2 to model_cell2 relationships. I'd expect 
associations between model2 and model_cell2 as well.

What version of the product are you using?

Codesmith Generator Standard 5.3.1 Revision 12440

Original issue reported on code.google.com by hutching...@gmail.com on 26 Nov 2010 at 5:59

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 29 Nov 2010 at 6:44

GoogleCodeExporter commented 9 years ago
http://community.codesmithtools.com/Template_Frameworks/f/67/p/11561/44276.aspx#
44276

Original comment by bniemyjski on 29 Nov 2010 at 6:44

GoogleCodeExporter commented 9 years ago
Hello,

I debugged this down to a bug in the PostgreSchemaProvider. Please contact 
CodeSmith Support (www.codesmithtools.com/contactus) for a nightly build of 
CodeSmith Generator which resolves this issue.

Thanks

-Blake Niemyjski

Original comment by bniemyjski on 29 Nov 2010 at 12:06