Hi There,

I have some data in which the relationships between objects are
defined via multiple properties and "BelongsTo" attributes. What I
would like to do is make a query that, given one object, I can
retrieve a list of all other objects that have referenced that object
via their properties.

NOTE: I do not have knowledge of these types until runtime, so the
solution may require reflection?

For example take these classes:

[ActiveRecord]
public class Person : ActiveRecordBase<Person>
{
        private int m_id;
        private Person m_mum;
        private Person m_dad;
        private Person m_bestFriend;

        [PrimaryKey]
        public int Id
        {
            get { return m_id; }
            set { m_id = value; }
        }

        [BelongsTo]
        public Person Mum
        {
            get { return m_mum; }
            set { m_mum= value; }
        }

        [BelongsTo]
        public Person Dad
        {
            get { return m_dad; }
            set { m_dad= value; }
        }

        [BelongsTo]
        public Person BestFriend
        {
            get { return m_bestFriend; }
            set { m_bestFriend= value; }
        }
}

[ActiveRecord]
public class Pet: ActiveRecordBase<Pet>
{
        private int m_id;
        private Person m_owner;

        [PrimaryKey]
        public int Id
        {
            get { return m_id; }
            set { m_id = value; }
        }

        [BelongsTo]
        public Person Owner
        {
            get { return m_mum; }
            set { m_mum= value; }
        }
}

I need to write a function that looks like:
ActiveRecordBase[] FindRelated(ActiveRecordBase object);

Such that if I pass in a Pet, it will return it's owner (if there is
one)
if I pass in a Person, it will return it's mum, dad, best friend, and
pet.

I thought I might be able to place a "HasManyToAny" attribute on each
object and simply return that entire list when the query is executed,
but the types are added dynamically and so adding metadata to the
attributes to define valid types that the objects may be isn't
possible in this case... unless it can be done without that?

If anyone has any suggestions on how this might be achieved I would
love to hear them. This is intended to make navigating a complex set
of relationships between objects easier as I'll be able to display a
relevant "See also" panel on the side of the object editor to quickly
jump to relevant related objects.

Similarly, this interface could be used to generate a graphic
'localised web' to visualise connections between objects.

Thanks for the help and suggestions

Josh

-- 
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.

Reply via email to