Hi all,

I posted this in the forum before I saw that the forum was replaced by
the list. Sorry for the repost, but anyway...

I'm running into a bit of trouble making an association within single
table inheritance work for me. The problem I'm running into is that
when one class's HasMany relationship is invoked, it doesn't seem to
be using the discriminator value for the class it's trying to pick up.

As an example, say I'm modeling a file system. We have a DB table
called 'items' with the following fields:

id: int (PK)
item_type: String (the discriminator for STI)
parent_id: int (points back to the items table)
name: String

Then I have two classes, File and Folder. First the File class:

[ActiveRecord("items",
  DiscriminatorColumn = "item_type",
  DiscriminatorType = "String",
  DiscriminatorValue = "File")]
public class File : ActiveRecordBase<File>
{
  // Properties and such...
}

Straightforward enough. Now we have the Folder class that has, for
sake of example, a collection of Files:

[ActiveRecord("items",
  DiscriminatorColumn = "item_type",
  DiscriminatorType = "String",
  DiscriminatorValue = "Folder")]
public class Folder : ActiveRecordBase<Folder>
{
  [HasMany(typeof (File), ColumnKey = "parent_id", Lazy = true)]
  public IList Files { get; set; }

  // Other properties..
}

Seems innocent enough, but when I call the Files property of a Folder
I'll get not only the Files but the Folders as well -- AR/NH isn't
using the discriminator for the File item when fetching the
collection. Looking at the SQL logs confirms this. I basically just
queries all items with the parent_id of the Folder, and leaves out the
item_type field altogether.

Any ideas what I'm doing wrong?

Thanks,
rusty

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to castle-project-users@googlegroups.com
To unsubscribe from this group, send email to 
castle-project-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to