def getBuildByArch(self, distroarchseries, archive):
        """See ISourcePackageRelease."""
        # First we try to follow any binaries built from the given source
        # in a distroarchseries with the given architecturetag and published
        # in the given (distroarchseries, archive) location.
        # (Querying all architectures and then picking the right one out
        # of the result turns out to be much faster than querying for
        # just the architecture we want).
        builds_by_arch = self.findBuildsByArchitecture(
            distroarchseries.distroseries, archive)
        build = builds_by_arch.get(distroarchseries.architecturetag)
        if build is not None:
            # If there was any published binary we can use its original build.
            # This case covers the situations when both source and binaries
            # got copied from another location.
            return build

        # If there was no published binary we have to try to find a
        # suitable build in all possible location across the distroseries
        # inheritance tree. See below.
        clause_tables = ['DistroArchSeries']
        queries = [
            "DistroArchSeries.id = BinaryPackageBuild.distro_arch_series AND "
            "BinaryPackageBuild.archive = %s AND "
            "DistroArchSeries.architecturetag = %s AND "
            "BinaryPackageBuild.source_package_release = %s" % (
            sqlvalues(archive.id, distroarchseries.architecturetag, self))]

        # Query only the last build record for this sourcerelease
        # across all possible locations.
        query = " AND ".join(queries)

        return BinaryPackageBuild.selectFirst(
            query, clauseTables=clause_tables,
            orderBy=['-date_created'])
    def getBuildByArch(self, distroarchseries, archive):
        """See ISourcePackageRelease."""
        # First we try to follow any binaries built from the given source
        # in a distroarchseries with the given architecturetag and published
        # in the given (distroarchseries, archive) location.
        # (Querying all architectures and then picking the right one out
        # of the result turns out to be much faster than querying for
        # just the architecture we want).
        builds_by_arch = self.findBuildsByArchitecture(
            distroarchseries.distroseries, archive)
        build = builds_by_arch.get(distroarchseries.architecturetag)
        if build is not None:
            # If there was any published binary we can use its original build.
            # This case covers the situations when both source and binaries
            # got copied from another location.
            return build

        # If there was no published binary we have to try to find a
        # suitable build in all possible location across the distroseries
        # inheritance tree. See below.
        clause_tables = ['DistroArchSeries']
        queries = [
            "DistroArchSeries.id = BinaryPackageBuild.distro_arch_series AND "
            "BinaryPackageBuild.archive = %s AND "
            "DistroArchSeries.architecturetag = %s AND "
            "BinaryPackageBuild.source_package_release = %s" %
            (sqlvalues(archive.id, distroarchseries.architecturetag, self))
        ]

        # Query only the last build record for this sourcerelease
        # across all possible locations.
        query = " AND ".join(queries)

        return BinaryPackageBuild.selectFirst(query,
                                              clauseTables=clause_tables,
                                              orderBy=['-date_created'])