Thanks or these replies Robert and Mark!
I guess that keeping the ancestors as a string in the database makes
more sense than I first thought. It is interesting that Robert refers
to this as ‘caching’ the family-tree, which obviously it is, but I’ve
not really thought of caching information like this (ie database level
relationships) before. Consequently, as Mark says it needs to be
updated whenever a name changes, which shouldn’t be too difficult to
do (cycle through all the descendants and update that row?).
This has the added advantage of acting as a sort of permalink row as
well. Thinking about pretty urls, it wouldn’t be too hard to use this
string to generate:
This would be the url that took you directly to Bart’s url. Could I
use the ‘/’ character as a separator at the DB level?
Robert - I really the idea of hashing the string to limit the length,
I’ve never thought of this as a use for hashing before, thanks!
Mark - I’m not sure what you mean by this:
you should put the name match into the
SQL conditions rather than in a Ruby loop.
I guess that you mean to use SQL rather than looping through ruby
arrays, but I’m afraid my SQL is very poor - I usually only use the
Rails helpers to do basic stuff. I’m struggling to follow your
example, but I guess that it corresponds to what Philip was alluding
to by saying to construct a joins string?
…And if I used this SQL method, which would be the most
efficient? I’m erring towards the ‘cached’ string method at the moment
as it easily allows uniqueness validations and as I mentioned could be
used to form pretty urls.
Thanks so much again to both of you - I’m really learning lots more
than I anticipated from this thread.