DAZ wrote:
> 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?).
Yes, you could use a recursive (tree) or batch (nested-set) traverse.
Or could actually do it in one statement, like
os = sanitize("/#{old_name}/")
ns = sanitize("/#{new_name}/")
Person.update_all "key = replace(key, #{os}, #{ns})",
['key like ?', "/path/to/#{old_name}/%"]
> 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:
>
> http://appname/people/abe/homer/bart
>
> 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?
Yes, good idea.
> 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?
person.children.find(:conditions => ['name = ?', name])
--
Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---