Ecto Assoziation mit einer Bedingung
Sagen wir, ich habe zwei Modelle,Post
undComment
und das Kommentarmodell kann 1 von 2 Typen sein,normal
undfancy
was durch die Spalte @ definiert itype
in demcomments
Tabelle
Nun möchte ich 2 Assoziationen zu meinem @ hinzufügPost
model, wo man sich auf ausgefallene Kommentare und auf normale bezieht, wie würde ich das machen? Also ich möchte so etwas:
has_many :fancy_comments, MyApp.Comment, where: [type: 0]
has_many :normal_comments, MyApp.Comment, where: [type: 1]