def match(self, models, results, relation):
        """
        Match the eagerly loaded results to their parents.

        :type models: list
        :type results: Collection
        :type relation:  str
        """
        dictionary = self._build_dictionary(results)

        for model in models:
            key = model.get_key()

            relationship = self.new_instance(model)

            if key in dictionary:
                collection = self._related.new_collection(dictionary[key])
            else:
                collection = self._related.new_collection()

            relationship.set_results(collection)

            model.set_relation(relation, relationship)

        return models
예제 #2
0
    def match(self, models, results, relation):
        """
        Match the eagerly loaded results to their parents.

        :type models: list
        :type results: Collection
        :type relation:  str
        """
        dictionary = self._build_dictionary(results)

        for model in models:
            key = model.get_key()

            relationship = self.new_instance(model)

            if key in dictionary:
                collection = self._related.new_collection(dictionary[key])
            else:
                collection = self._related.new_collection()

            relationship.set_results(collection)

            model.set_relation(relation, relationship)

        return models
    def _hydrate_pivot_relation(self, models):
        """
        Hydrate the pivot table relationship on the models.

        :type models: list
        """
        for model in models:
            pivot = self.new_existing_pivot(self._clean_pivot_attributes(model))

            model.set_relation('pivot', pivot)
예제 #4
0
    def _hydrate_pivot_relation(self, models):
        """
        Hydrate the pivot table relationship on the models.

        :type models: list
        """
        for model in models:
            pivot = self.new_existing_pivot(self._clean_pivot_attributes(model))

            model.set_relation('pivot', pivot)
    def init_relation(self, models, relation):
        """
        Initialize the relation on a set of models.

        :type models: list
        :type relation:  str
        """
        for model in models:
            model.set_relation(relation, self._related.new_collection())

        return models
예제 #6
0
    def init_relation(self, models, relation):
        """
        Initialize the relation on a set of models.

        :type models: list
        :type relation:  str
        """
        for model in models:
            model.set_relation(relation, Result(self._related.new_collection(), self, model))

        return models
    def _match_to_morph_parents(self, type, results):
        """
        Match the results for a given type to their parent.

        :param type: The parent type
        :type type: str

        :param results: The results to match to their parent
        :type results: Collection
        """
        for result in results:
            if result.get_key() in self._dictionary.get(type, []):
                for model in self._dictionary[type][result.get_key()]:
                    model.set_relation(self._relation, result)
예제 #8
0
    def _match_to_morph_parents(self, type, results):
        """
        Match the results for a given type to their parent.

        :param type: The parent type
        :type type: str

        :param results: The results to match to their parent
        :type results: Collection
        """
        for result in results:
            if result.get_key() in self._dictionary.get(type, []):
                for model in self._dictionary[type][result.get_key()]:
                    model.set_relation(self._relation, result)