sdispater / eloquent

The Eloquent ORM provides a simple yet beautiful ActiveRecord implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for related name in relationships declaration

sdispater opened this issue · comments

To avoid issues with circular references when declaring relationships, the relationship methods should support declaring the related model with its table name.

class Post(Model):

    @property
    def tags(self):
        return self.morph_to_many('tags', 'taggable')


class Video(Model):

    @property
    def tags(self):
        return self.morph_to_many('tags', 'taggable')


class Tag(Model):

    @property
    def posts(self):
        return self.morphed_by_many('posts', 'taggable')

    @property
    def videos(self):
        return self.morphed_by_many('videos', 'taggable')