Access other module parts in migrations

Topics: Writing modules
Aug 1, 2013 at 10:42 AM
I'm trying to find a way of accessing a content part from another module in migrations.

Currently i have tried this:
using WebShop.Models;
using Products.Models;

namespace WebShop
{
    public class Migrations : DataMigrationImpl
    {
.....
        SchemaBuilder.CreateForeignKey("OrderDetail_Product", "OrderDetailRecord", new[] { "ProductId" }, "Products.Models.OtherProductPartRecord", new[] { "Id" });
When trying this i get an error saying:
"The specified table does not exist. [ WebShop_Products.OtherProductPartRecord ]"

Is there any way to access the part from a different migrations?
Coordinator
Aug 1, 2013 at 8:33 PM
I'm sorry but this is extremely confusing. What exactly are you trying to do?
Aug 1, 2013 at 10:15 PM
I do apologize, i'm finding it difficult to describe because i'm quite new to Orchard and C#

Basically, i'm following this tutorial and i'm down to the bit where i'm setting up the migrations and the Foreign Key

I'm trying to implement the following line:
SchemaBuilder.CreateForeignKey("OrderDetail_Product", "OrderDetailRecord", new[] { "ProductId" }, "ProductRecord", new[] { "Id" });
However, i cannot access the "ProductRecord" part as it is located a different module with a different name("Products" module, named "OtherProductPartRecord") and its table is created in a different migrations file.

You might be able to see what i tried to do in my first comment, which didn't work. I have also tried:
SchemaBuilder.CreateForeignKey("OrderDetail_Product", "OrderDetailRecord", new[] { "ProductId" }, typeof<OtherProductPartRecord>.Name, new[] { "Id" });
Which also didn't work.

Is there any way to allow the migrations of the "WebShop" module to access the OtherProductPartRecord located in the "Products" module?

Hopefully i explained it a little better this time!
Coordinator
Aug 2, 2013 at 12:04 AM
Why does it have to be in a separate module?
Aug 2, 2013 at 9:45 AM
They doesn't have to be separate, but for the sake of learning, I'm wondering if what I'm asking is actually possible to achieve through code.
Coordinator
Aug 4, 2013 at 5:16 AM
I don't see how this makes sense, sorry. The migrations for a part should be in the same module as that part. I don't see a scenario for this.
Aug 5, 2013 at 9:30 AM
Fair enough, I appreciate your input.

I have decided to merge the two modules together as it does seem to make more sense.

Thanks again
Aug 5, 2013 at 2:22 PM
If you need to access a table (through a Part) generated by a different module, I'd expect that declaring a dependency in your module.txt file would help executing the Migrations in the correct order. Orchard descends down the dependency chain to ensure that first the Migrations of a dependent module will be run before the Migrations of the depending module.

That might have helped with your problem.

--


2013/8/5 ImpactUK <[email removed]>

From: ImpactUK

Fair enough, I appreciate your input.

I have decided to merge the two modules together as it does seem to make more sense.

Thanks again

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Aug 5, 2013 at 3:01 PM
Edited Aug 5, 2013 at 3:01 PM
I referenced and declared a dependency to the "Products" module, but the problem was that the migrations was prefixing all of the database names with the name of the module.
Eg:
WebShop_CustomerPartRecord
Products_ProductPartRecord