This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
as an example, I have 3 tables:
UserActivity UserGroup UserGroupUserActivity
UserGroupUserActivity has a composite primary key composed of UserGroupId and UserActivityId (both foreign keys) as well as Allow and Deny properties. I have a through association between UserGroup and UserActivity through table UserGroupUserActivity.
My question is this: how can I make it so the objects in the UserActivity collection on a UserGroup object have Allow and Deny properties? is this possible? I do not require the relationship to also apply to the collection of UserGroup objects in UserActivity objects, but it's not a problem if that relationship exists. |
|
|
You can't make it so that the UserActivity objects have Allow and Deny properties, but you can set these properties on the *intermediate* (through) entities -- the UserGroupUserActivity objects. Think of it as: Allow and Deny are attributes of a group-activity relationship rather than of the activity itself; a relationship is represented by a through entity; therefore Allow and Deny go on the through entity. To add properties to the through entity in the designer, configure the through association to have an explicit through entity instead of an auto through entity. (You have probably already done this if you are using a composite key on the through entity.) See http://www.mindscapehq.com/blog/index.php/2009/09/17/many-to-many-associations-in-the-lightspeed-designer/ and http://www.mindscapehq.com/blog/index.php/2010/10/19/many-to-many-associations-from-designer-to-database/ for examples of through associations with explicit through entities. Now you have a shape representing the through entity (the UserGroupUserActivity in your case), you can right-click it and Add Entity Property to create the Allow and Deny properties. To access these properties, use the one-to-many associations from the "main" entities to the through entity, e.g. UserGroup.UserGroupUserActivities. This gets you the through entities (as opposed to the UserActivity entities) so you can examine or modify their Allow and Deny properties. See http://www.mindscapehq.com/forums/Thread.aspx?ThreadID=3764 for another example. |
|
|
ok that makes sense, but I'm having some trouble understanding how I am supposed to add those properties to the through association. I don't see anywhere in the designer or anywhere else that I can add them. |
|
|
You don't add them to the through association. You add them to the through entity. Take a look at http://www.mindscapehq.com/blog/index.php/2009/09/17/many-to-many-associations-in-the-lightspeed-designer/. If your association looks like the second screenshot, i.e. with a UserGroupUserActivity entity visible on the designer surface, then you can add the properties to the UserGroupUserActivity entity just like any other entity (right-click > Add New Entity Property). If your association looks like the third screenshot, i.e. without a UserGroupUserActivity entity shape, then you need to make the through entity visible. Right-click the association and choose Convert to Explicit Through Entity. This will get you to the situation shown in the second screenshot and you can go from there as above. |
|
|
it looks like the second screenshot, but those properties already exist as columns on that table in the database. What I want to do is something like this:
UserGroup myUserGroup; bool isAllow = myUserGroup.UserActivities.First().Allow;
and not have to do this:
bool isAllow = myUserGroup.UserGroupUserActivities.First(o => o.UserActivity == someUserActivity).Allow;
can this be done in lightspeed? |
|
|
No. It is not possible to have the Allow property on the UserActivity object because Allow is not an attribute of an activity, it is an attribute of a relationship between an activity and a group. (Suppose two groups were related to the same activity a, one with Allow=true and one with Allow=false. a.Allow can't hold both values. And activities have identity, so we can't return different activity objects for the two groups.) Instead, use methods and/or properties in the partial class to encapsulate the fiddling around with the through objects: partial class UserGroup { |
|
|
I guess it's not a big deal really... I just thought it would be nice to aggregate the two entities in the context of the through association. |
|