Search code examples
entitypersistentyesod

Yesod/Persistent field with Eq


In the Persistent chapter of the Yesod book, a certain field is given an Eq suffix, but it is never explained why. In the Relations section, we see the following models:

Person
    name String
    deriving Show
Car
    ownerId PersonId Eq
    name String
    deriving Show

Soon after, we are shown:

Person
    name String
Store
    name String
PersonStore
    personId PersonId
    storeId StoreId
    UniquePersonStore personId storeId

Aside from the latter being many-to-many, what is the difference? I've gathered on IRC that the Eq suffix enables joining on that field. If that is the case, why would a person ever not want the Eq suffix? Are there any other cases that Eq should be used aside from relations?


Solution

  • I thought I got rid of all of those... it's just a holdover from older days of Persistent where the Eq was required. These days, it doesn't do anything, and you can compare equality on all fields.

    Equality testing can be used for a lot of cases, such as "find all posts by an author":

    selectList [PostAuthor ==. userId] [Desc PostDate]