ActiveRecord not creating a table for HasMany relationship against object with Single Table Inheritance

0 views
Skip to first unread message

JakeS

unread,
Aug 19, 2009, 12:14:36 PM8/19/09
to Castle Project Users
I've got an inherited object defined like this:

[ActiveRecord("CompanyUsers",
DiscriminatorColumn = "type",
DiscriminatorType = "String",
DiscriminatorValue = "CompanyUser")]
public abstract class UserBase : ModelBase<UserBase>
{
// some props and methods
}

[ActiveRecord(DiscriminatorValue = "TechnicianUser")]
public class Technician : UserBase
{
// other props
private IList<ScheduledInstall> _scheduledInstalls= new
List<ScheduledInstall>();
[HasMany(typeof(ScheduledInstall), Table = "ScheduleForTech",
ColumnKey = "ScheduleID", Inverse=true)]
public IList<ScheduledInstall> Schedule
{
get
{
if(_scheduledInstalls==null){_scheduledInstalls=new
List<ScheduledInstall>();}
return _scheduledInstalls;
}
set
{
_scheduledInstalls = value;
}
}
}

And then the ScheduledInstall class references the Technician like
this:
[ActiveRecord]
public class ScheduledInstall : ModelBase<ScheduledInstall>
{
[BelongsTo("TechnicianID")]
public Technician Technician { get; set; }
}

But when I run Castle.ActiveRecord.ActiveRecordStarter.CreateSchema(),
it's not creating the ScheduleForTech table like I expected. Can
someone help me figure out what I'm doing wrong?

Markus Zywitza

unread,
Aug 19, 2009, 12:49:08 PM8/19/09
to castle-pro...@googlegroups.com
many-to-one-relationships are stored on the many-side of the relationship. In your case this is the ScheduledInstall type. Simply omit Table and ColumnKey on the HasMany and AR will guess them from the type referred to.

If you need a many-to-many-relationship, you have to use HasAndBelongsToMany instead.

-Markus

2009/8/19 JakeS <jakest...@gmail.com>

JakeS

unread,
Aug 19, 2009, 1:41:22 PM8/19/09
to Castle Project Users
Thank you very much. It's working exactly as it should.
Reply all
Reply to author
Forward
0 new messages