vapor / fluent

Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
https://docs.vapor.codes/4.0/fluent/overview/
MIT License
1.32k stars 172 forks source link

to generic or not to generic #184

Closed tanner0101 closed 7 years ago

tanner0101 commented 7 years ago

Using Protocol.Type

class User: Model {
    var teams: Siblings<Team> {
        return siblings(through: Project.self)
    }
}

Pros:

Cons:

Using Generics

class User: Model {
    var teams: Siblings<User, Team, Project> {
        return siblings()
    }
}

This syntax would be awesome but Pivot<> can't be a default argument and self cannot be used to resolve the generic requirement.

class User: Model {
    lazy let teams = Siblings(from: self, to: Team.self)
}

Pros:

Cons:

tanner0101 commented 7 years ago

Ream

class User: Object {
    let teams = LinkingObjects(fromType: Team.self, property: "users")
}
tanner0101 commented 7 years ago

In core data you set up two to-many relationships that point to each other then some Xcode magic makes this happen:

let usersTeams = aUser.valueForKeyPath("teams.team")
tanner0101 commented 7 years ago

Laravel

class User extends Model
{
    public function teams()
    {
        return $this->belongsToMany('App\Team', 'projects', 'user_id', 'team_id');
    }
}
tanner0101 commented 7 years ago

Rails

class User < ApplicationRecord
  has_many :teams through, :projects
end
hhanesand commented 7 years ago

I'm all for choosing the "fast" option, as that's one of the main reasons I chose to use vapor.

tanner0101 commented 7 years ago

@hhanesand that's what we ended up going with :)