SubSonic Forums
All Your Database Are Belong To Us

Migrations and ManyToMany

Latest post 10-13-2008 8:28 AM by jwynia. 2 replies.
  • 10-09-2008 2:05 PM

    • jwynia
    • Top 500 Contributor
    • Joined on 04-16-2008
    • Posts 7

    Migrations and ManyToMany

    For previous Subsonic projects where I set the tables up directly in the database, when I needed a ManyToMany table for mapping things across, I created that table with one column for each of the related tables and made all of those columns into a composite key. That has, in the past, made Subsonic do the "right" thing (not that I'm assuming that what I've been doing is the "right" way to achieve it).

    I was intrigued by the migrations recently when I heard them described, so decided to use them on a new project. The problem I've got is that all of the examples leave out the ManyToMany setup. In and of itself, that wouldn't be a big deal, except that even in the API, I can't see how you'd either created the composite keys like I'm used to or any other way to create ManyToMany tables.

    All of the methods for creating tables and primary keys are all about one column and if, for example, you build up the 2-3 columns manually (making them all primary with IsPrimaryKey) and add them to the table, the duplicate primary key exception is thrown.

    I know from my early experience with Subsonic that adding another column to *be* the primary key breaks the convention and the functionality for the Table1Table2Map method of gettting nice ManyToMany objects.

    I also know the migrations are a relatively new feature, so it's entirely possible that this is just not there yet, but I want to know for sure before moving on to a more hackish solution.

    Filed under:
  • 10-13-2008 12:27 AM In reply to

    Re: Migrations and ManyToMany

    I don't think that is posible as of now but I think you can tell the migration to generate any SQL script for you so maybe that can help for now.

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 10-13-2008 8:28 AM In reply to

    • jwynia
    • Top 500 Contributor
    • Joined on 04-16-2008
    • Posts 7

    Re: Migrations and ManyToMany

    I kind of figured that. I looked at MigratorDotNet for a bit, which supports them, but at the moment I'm prototyping, not building a production system and the focus on Nant and MSBuild to get the migrations built wasn't as appealing as exactly what you're suggesting. So, I just came back and used Execute() statements to move forward.

    What I did was use Execute to get the table and primary keys built and then moved back to Migration methods to do the rest of the setup. Those 2 steps need to be in separate migrations or it can't find the table, but otherwise, it worked.

     

     

Page 1 of 1 (3 items) | RSS