Fix issue with trying to get metadata instance from a wrong class

One of my models was using a mixin class/multiple inheritance and the builder only looked at the first base for the metadata class and promptly died noting that the mixin class does not have a metadata property.

Fix this up to look at all bases to try and find the metadata instance to use.