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
Ejemplo n.º 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 associate(self, model):
        """
        Associate the model instance to the given parent.

        :type model: orator.Model

        :rtype: orator.Model
        """
        self._parent.set_attribute(self._foreign_key, model.get_key())
        self._parent.set_attribute(self._morph_type, model.get_morph_class())

        return self._parent.set_relation(self._relation, model)
Ejemplo n.º 4
0
    def associate(self, model):
        """
        Associate the model instance to the given parent.

        :type model: orator.Model

        :rtype: orator.Model
        """
        self._parent.set_attribute(self._foreign_key, model.get_key())
        self._parent.set_attribute(self._morph_type, model.get_morph_class())

        return self._parent.set_relation(self._relation, model)
    def save(self, model, joining=None, touch=True):
        """
        Save a new model and attach it to the parent model.

        :type model: orator.Model
        :type joining: dict
        :type touch: bool

        :rtype: orator.Model
        """
        if joining is None:
            joining = {}

        model.save({'touch': False})

        self.attach(model.get_key(), joining, touch)

        return model
Ejemplo n.º 6
0
    def save(self, model, joining=None, touch=True):
        """
        Save a new model and attach it to the parent model.

        :type model: orator.Model
        :type joining: dict
        :type touch: bool

        :rtype: orator.Model
        """
        if joining is None:
            joining = {}

        model.save({"touch": False})

        self.attach(model.get_key(), joining, touch)

        return model