Shouldn't context come into play here...given that with a wish list we care
about the user's wish lists more than we care about the list belonging to a
user (jeez that seems convoluted).

I'm thinking in terms of an "Aggregate Root".  Admittedly I'm new to DDD but
why in this scenario do I want the uni on the many side?

On Tue, Oct 21, 2008 at 7:34 PM, Ayende Rahien <[EMAIL PROTECTED]> wrote:

> It is not a bad idea, it is just that you need to understand what it means
> to put the association on the other end.It is very natural for the
> wishlist to have a user property, because it is in its own table.
> When you have a one to many association, by definition it is not on the
> same table, so it goes as a separate statement.
>
> If you don't want bidi, then you uni on the many to one side seems natural.
>
>
> On Wed, Oct 22, 2008 at 2:29 AM, Tim Barcz <[EMAIL PROTECTED]> wrote:
>
>> Can you expound a bit...I'm thinking about this in the context of someone
>> new to DDD.  My thought is that a WishList belongs to a user.  We don't
>> typically care about wishlists by themselves, we only care about them in the
>> context of a user.
>>
>> Can you explain why this is a bad idea and I'd want the unidirectional the
>> other way?
>>
>>
>> On Tue, Oct 21, 2008 at 7:10 PM, Ayende Rahien <[EMAIL PROTECTED]> wrote:
>>
>>> It is not bad, the problem is that you are trying to make it
>>> unidirectional in the wrong direction. The way this works is that the
>>> wishlist belongs to a user. This means that you usually have the uni
>>> directional from that, and query from the user if you need to.
>>> That is a good idea anyway, since that means that you start thinking
>>> about things like unbounded result sets.
>>>
>>>
>>> On Tue, Oct 21, 2008 at 5:54 PM, Tim Barcz <[EMAIL PROTECTED]> wrote:
>>>
>>>> Below are the mapping files....however the problem I see is that I want
>>>> to do a unidirectional mapping.  There are two tables (Users and 
>>>> WishLists),
>>>> of which WishLists has a foreign-key ref back to users.  A Wishlist doesn't
>>>> exists outside the context of a user.  I'm reading some places where this 
>>>> is
>>>> "bad" in NH.  I would like to keep this unidirectional as it feels more
>>>> correct.
>>>>
>>>> Suggestions.
>>>>
>>>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
>>>> namespace="NHWishList.Model" assembly="NHWishList">
>>>>     <class name="User" table="Users">
>>>>         <id name="UserId" column="UserId" type="Int32"
>>>> unsaved-value="0">
>>>>             <generator class="native" />
>>>>         </id>
>>>>         <property name="First" column="First" length="50"
>>>> not-null="true" />
>>>>         <property name="Last" column="Last" length="50" not-null="true"
>>>> />
>>>>
>>>>         <bag name="WishLists" cascade="all" lazy="true">
>>>>             <key column="UserId"/>
>>>>             <one-to-many class="WishList"/>
>>>>         </bag>
>>>>     </class>
>>>> </hibernate-mapping>
>>>>
>>>> <?xml version="1.0" encoding="utf-8" ?>
>>>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
>>>> namespace="NHWishList.Model" assembly="NHWishList">
>>>>     <class name="WishList" table="WishLists">
>>>>         <id name="WishListId" column="WishListId" type="Int32"
>>>> unsaved-value="0">
>>>>             <generator class="native" />
>>>>         </id>
>>>>         <property name="Name" column="Name" length="50" not-null="true"
>>>> />
>>>>         <many-to-one name="Owner" column="UserId" class="User"
>>>> not-null="false" />
>>>>     </class>
>>>> </hibernate-mapping>
>>>>
>>>>
>>>> On Tue, Oct 21, 2008 at 10:46 AM, Gabriel Schenker <
>>>> [EMAIL PROTECTED]> wrote:
>>>>
>>>>> show your mappings please
>>>>>
>>>>>
>>>>> On Tue, Oct 21, 2008 at 5:44 PM, Tim Barcz <[EMAIL PROTECTED]> wrote:
>>>>>
>>>>>> Ok that's well and good...so I've got unidirectional going on....but
>>>>>> am seeing strangeness
>>>>>>
>>>>>> NHibernate: INSERT INTO Users (First, Last) VALUES (@p0, @p1); select
>>>>>> SCOPE_IDENTITY(); @p0 = 'Tim', @p1 = 'Barcz'
>>>>>> NHibernate: INSERT INTO WishLists (Name, UserId) VALUES (@p0, @p1);
>>>>>> select SCOPE_IDENTITY(); @p0 = 'Sample', @p1 = ''
>>>>>> NHibernate: UPDATE WishLists SET UserId = @p0 WHERE WishListId = @p1;
>>>>>> @p0 = '8', @p1 = '1'
>>>>>>
>>>>>> Why does this have to be three calls?  After the first call, the
>>>>>> second should have the ID from the first (the userId).  The update 
>>>>>> should be
>>>>>> unnecessary.
>>>>>>
>>>>>> Tim
>>>>>>
>>>>>>
>>>>>> On Tue, Oct 21, 2008 at 1:40 AM, Gabriel Schenker <
>>>>>> [EMAIL PROTECTED]> wrote:
>>>>>>
>>>>>>> first of all to decrease complexity I would only use uni-directional
>>>>>>> relations in my domain model (even though in the database any relation 
>>>>>>> is
>>>>>>> bi-directional) that is, a wishlist does not have to know any thing 
>>>>>>> about a
>>>>>>> user or about its manager
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Oct 20, 2008 at 11:16 PM, Tim Barcz <[EMAIL PROTECTED]>wrote:
>>>>>>>
>>>>>>>> I have a user object and the user can have a number of wishlists.
>>>>>>>>
>>>>>>>> Instead of having methods on user (ie. User.AddWishlist,
>>>>>>>> User.RemoveWishlist), I have a WishListManager which has these methods 
>>>>>>>> on
>>>>>>>> it.
>>>>>>>>
>>>>>>>> Persistent entities include, WishList and WishList item, which
>>>>>>>> relate back to the user through the WishListManager.
>>>>>>>>
>>>>>>>> How would I set up this mapping in NHibernate?  Can someone point me
>>>>>>>> in the right direction?
>>>>>>>>
>>>>>>>> Tim
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to