I'm going to simplify the problem I'm having. So let's suppose we have an NHibernate domain of pets, with Spot the dog, Fluffy the cat, Hunter the cat, and SSSS the snake so in the db these guys would look like:
ID Name Species 1 Spot 1 2 Fluffy 2 3 Hunter 2 4 SSSS 3
And we have a species table
ID Species 1 Dog 2 Cat 3 Snake
And let's say we have a skin-type table with these two entries
ID Type 1 Furry 2 Scaley
And a look up table that looks like
Species Type 1 1 2 1 3 2
How do I map this so that will pull the type of skin in with the object.
I've looked at a mapping file like this
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="menagerie" assembly="menagerie"> <class name="Pet" table="Pets"> <id name="Id"> <column name="id" /> <generator class="native" /> </id> <property name="Name" /> <many to one name="Species" class="PetSpecies" column="Species" cascade="all" /> <bag name="SkinType" table="Species_SkinType" cascade="none" lazy="false"> <key column="Species" /> <many-to-many class="SkinType" column="[type]" /> </bag> </class> </hibernate-mapping>
However, the bag that's supposed to be filled with the pet's skin type wants to use the pet's id as the look up key value, not the pet's species. How do I get it to use the pet's species to populate the skintype for the pet?
|