The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Conflicting relationships

Last post 10-12-2007, 3:54 PM by PurpleFlux. 3 replies.
Sort Posts: Previous Next
  •  10-12-2007, 6:35 AM 5816

    Conflicting relationships

    I am using ES 2007.0.730.0 but I also tested on 2007.1.1001.0 beta. MyGeneration is 1.2.0.7.

    With the database schema below I get compile errors in my solution. BusinessObjects.Jobs already contains a definition for "UpToLocationsCollection" and other errors due to the duplication. Frankly I don't quite get why ES is trying to make a direct connection between Jobs and Locations anyway, they do not have a direct relationship. I would have expected to have to do Jobs.SecurityCodeCollectionByFKJobID and then SecurityCode.UpToLocationsByFKLocationID to get from Jobs to Locations.

    I found the problem in one project and made this simpler test example. I also created a test solution to go with it but I doubt you'll need it as it is a problem with the ES code compiling, not with how I am using it. But if you want it, let me know and I'll send it too.

     

    Here is the create database script (MS SQL 2005):

    Code:
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Locations]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[Locations](
    	[LocationID] [int] IDENTITY(1,1) NOT NULL,
    	[Name] [varchar](50) NOT NULL,
     CONSTRAINT [PK_Locations] PRIMARY KEY CLUSTERED 
    (
    	[LocationID] ASC
    )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Jobs]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[Jobs](
    	[JobID] [int] IDENTITY(1,1) NOT NULL,
    	[Name] [varchar](50) NOT NULL,
     CONSTRAINT [PK_Jobs] PRIMARY KEY CLUSTERED 
    (
    	[JobID] ASC
    )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SecurityCode]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[SecurityCode](
    	[FKJobID] [int] NOT NULL,
    	[FKLocationID] [int] NOT NULL,
    	[Value] [varchar](50) NULL,
     CONSTRAINT [PK_SecurityCode] PRIMARY KEY CLUSTERED 
    (
    	[FKJobID] ASC,
    	[FKLocationID] ASC
    )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MailingList]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[MailingList](
    	[FKJobID] [int] NOT NULL,
    	[FKLocationID] [int] NOT NULL,
    	[Value] [varchar](50) NULL,
     CONSTRAINT [PK_MailingList] PRIMARY KEY CLUSTERED 
    (
    	[FKJobID] ASC,
    	[FKLocationID] ASC
    )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_SecurityCode_Jobs]') AND parent_object_id = OBJECT_ID(N'[dbo].[SecurityCode]'))
    ALTER TABLE [dbo].[SecurityCode]  WITH CHECK ADD  CONSTRAINT [FK_SecurityCode_Jobs] FOREIGN KEY([FKJobID])
    REFERENCES [dbo].[Jobs] ([JobID])
    GO
    ALTER TABLE [dbo].[SecurityCode] CHECK CONSTRAINT [FK_SecurityCode_Jobs]
    GO
    IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_SecurityCode_Locations]') AND parent_object_id = OBJECT_ID(N'[dbo].[SecurityCode]'))
    ALTER TABLE [dbo].[SecurityCode]  WITH CHECK ADD  CONSTRAINT [FK_SecurityCode_Locations] FOREIGN KEY([FKLocationID])
    REFERENCES [dbo].[Locations] ([LocationID])
    GO
    ALTER TABLE [dbo].[SecurityCode] CHECK CONSTRAINT [FK_SecurityCode_Locations]
    GO
    IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MailingList_Jobs]') AND parent_object_id = OBJECT_ID(N'[dbo].[MailingList]'))
    ALTER TABLE [dbo].[MailingList]  WITH CHECK ADD  CONSTRAINT [FK_MailingList_Jobs] FOREIGN KEY([FKJobID])
    REFERENCES [dbo].[Jobs] ([JobID])
    GO
    ALTER TABLE [dbo].[MailingList] CHECK CONSTRAINT [FK_MailingList_Jobs]
    GO
    IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MailingList_Locations]') AND parent_object_id = OBJECT_ID(N'[dbo].[MailingList]'))
    ALTER TABLE [dbo].[MailingList]  WITH CHECK ADD  CONSTRAINT [FK_MailingList_Locations] FOREIGN KEY([FKLocationID])
    REFERENCES [dbo].[Locations] ([LocationID])
    GO
    ALTER TABLE [dbo].[MailingList] CHECK CONSTRAINT [FK_MailingList_Locations]
    
  •  10-12-2007, 6:49 AM 5818 in reply to 5816

    Re: Conflicting relationships

    Here is a database diagram of the above-posted schema

    database diagram
  •  10-12-2007, 3:03 PM 5829 in reply to 5818

    Re: Conflicting relationships

    There are some unusual relationships for which EntitySpaces default hierarchical settings will not generate unique names. In your case, you have two many to many between the same two tables. This can also happen for ternary and higher relationships. To add an additional tie-breaker for the generated names, you'll have to:

    • Run the "Set esPlugin Settings" template.
    • Switch to the Hierarchical tab.
    • Check "Use the associative table name for ManyToMany".
    • Click OK.
    • Regenerate.

     


    David Neal Parsons
    www.entityspaces.net
  •  10-12-2007, 3:54 PM 5833 in reply to 5829

    Re: Conflicting relationships

    Ok, thank you, I didn't know about that workaround.
View as RSS news feed in XML