Maybe I was unclear. BelongsTo won't help here, Any is the reight attribute. You have to specify
HasMany(typeof(Journal), ColumnKey="...", Table="...") This should work. -Markus 2009/8/4 jsmorris <[email protected]> > > Moved from dev list...my apologies for asking my question on the wrong > list. > > I now understand that I need the BelongsTo, but my problem is > constructing the correct BelongsTo in this situation. All my attempts > have failed. > > So, my Journal class needs a BelongsTo to associate it to either a Foo > or Bar, so if I define this > > [BelongsTo("JournalableId", Table = "Journals")] > public IJournalable Journalable { get; set; } > > I get the the error message. If I type the property to either of my > concrete types Foo or Bar, I do not get an error. > > [BelongsTo("JournalableId", Table = "Journals")] > public Foo Journalable { get; set; } > > or > > [BelongsTo("JournalableId", Table = "Journals")] > public Bar Journalable { get; set; } > > I feel that I need to be able to specify a type to the BelongsTo. I > was attempting to use the Any attribute to specify my metatype, > IJournalable, as well as the concrete types, Foo and Bar, for this > association. I believe that my Journals table would end up with > columns Id, JournalableId, JournalableType where JournalableType would > be either Foo or Bar. > > Is this type of association even possible? > > Thanks, > Jason > > > > On Fri, Jul 31, 2009 at 7:34 PM, Markus Zywitza<[email protected]> > wrote: > > Hint: It's already explained in the exception: If you don't have a > BelongsTo > > (Any doesn't count), you need to specify ColumnKey and Table. > > > > -Markus > > > > 2009/7/31 jsmorris <[email protected]> > >> > >> I am having trouble setting up my AR relationships. I have tried so > >> many things, but nothing seems to work. Here is what I am trying to > >> do. > >> > >> Foo has many Journals. Bar has many Journals. A Journal can belong to > >> either Foo or Bar. > >> > >> If I try the mapping I have below, I get the following error > >> > >> Castle.ActiveRecord.Framework.ActiveRecordException: ActiveRecord > >> tried to infer details about the relation Bar.Journals but it could > >> not find a 'BelongsTo' mapped property in the target type > >> Intel.TraX.Tests.Data.Store.Journal > >> > >> I am probably way off on what needs to be done, but I am looking for > >> any help to point me in the right direction. > >> > >> Thanks, > >> Jason > >> > >> [ActiveRecord] > >> public class Journal : DomainObject<Journal> > >> { > >> [Any(typeof(Int32), MetaType = typeof(IJournalable), > >> TypeColumn = "JournalableType", IdColumn = "JournalableId", Cascade = > >> CascadeEnum.SaveUpdate)] > >> [Any.MetaValue("Foo", typeof(Foo))] > >> [Any.MetaValue("Bar", typeof(Bar))] > >> public IJournalable Journalable { get; set; } > >> } > >> > >> public interface IJournalable {} > >> > >> [ActiveRecord] > >> public class Foo : DomainObject<Foo>, IJournalable > >> { > >> [HasMany(ColumnKey = "JournalableId")] > >> public IList<Journal> Journals { get; set; } > >> } > >> > >> [ActiveRecord] > >> public class Bar : DomainObject<Bar>, IJournalable > >> { > >> [HasMany(ColumnKey = "JournalableId")] > >> public IList<Journal> Journals { get; set; } > >> } > >> } > >> > >> > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
