Builds a new record subject to the restrictions in the query.
        Will build intermediate (join table) records as needed, and links them
        to the returned record so that they are saved when the returned record
        is.

def build(self, **kwargs):
        """
        Builds a new record subject to the restrictions in the query.
        Will build intermediate (join table) records as needed, and links them
        to the returned record so that they are saved when the returned record
        is.
        """
        build_args = dict(self.where_query)
        build_args.update(kwargs)
        record = self.model(**record_args(build_args))
        if self.join_args:
            # EXAMPLE:
            # Say we have a many-to-many relation like so:
            #   Post -> Tagging -> Tag
            # If we are adding a tag to a post, we need to create the tagging
            # in addition to the tag. To do this, we add a "related record" to
            # the tag which is the tagging. By building the previous record,
            # if it exists, we can recursively build a long object tree.
            # That is, when we do post.tags(), we get a query that looks like:
            # Query(Tag).joins("taggings").where(taggings={"post_id":post.id})
            # The call to "build" then creates a tag using kwargs and the where
            # constraint, and creates a tagging that looks like:
            # Tagging(post_id = post.id) and adds it to the tag's related
            # records. The tagging's tag_id is added once the tag is saved
            # which is the first time it gets an id
            # Join args will never have just one element
            next_to_build = getattr(self.record, self.join_args[-2]['table']).build()
            record._related_records.append(next_to_build)
        return record