Wednesday, April 15, 2009

Join is working

I have the join working but it's not pretty.

_tags = DBObject.WhereJoin("user_id", "=", this.ID, typeof(DBTag), "tag_user", "tag_id", "id", DBUser._conn);


Right now, in the Where you have to specify all the information about the Join, the table, the columns, etc. and it doesn't use a property but the column name (because there is no object for the join table.)

I think I'm going to try and move some of this information into the attribute. I also noticed that I need something like a Helper object, or something to help me get information about the object and prevent from calling the same methods over and over again every time I need the same bit of information.

For the Join, I need to know:
  • Join Table name
  • Join column on the join table.
  • Join column on the normal table
  • Where Column on the join table
  • Where value

Do I want a static Search column for the join? Or do I want to be able specify that in the method?
In my example:
SELECT * FROM tag JOIN tag_user ON tag_user.tag_id = tag.id WHERE tag_user.user_id = 2;

This gets all the tags for the user, so this will always be the case. The easiest would be to assume this is the default until I have evidence to the contrary.

No comments: