fukamachi / mito

An ORM for Common Lisp with migrations, relationships and PostgreSQL support
292 stars 31 forks source link

Deflate function does not applied to arguments of find-dao #52

Closed svetlyak40wt closed 5 years ago

svetlyak40wt commented 5 years ago

For example, if I have a model like that:

(defclass social-profile ()
  ((user :col-type user
         :initarg :user
         :accessor get-user)
   (service :col-type (:text)
            :initarg :service
            :reader get-service
            :inflate (lambda (text)
                       (make-keyword (string-upcase text))))
  (:documentation "Represents a User's link to a social service.
                   User can be bound to multiple social services.")
  (:metaclass mito:dao-table-class))

then I can do:

(mito:find-dao 'social-profile :service :github)

Mito thinks that :github is a column name and Postgres throws an error:

DB Error: column "github" does not exist (Code: 42703)
   [Condition of type DBI.ERROR:<DBI-PROGRAMMING-ERROR>]

Restarts:
 0: [RETRY] Retry SLY mREPL evaluation request.
 1: [*ABORT] Return to SLY's top level.
 2: [ABORT] abort thread (#<THREAD "sly-channel-1-mrepl-remote-1" RUNNING {1012AF06B3}>)

Backtrace:
 0: ((:METHOD DBI.DRIVER:PREPARE (DBD.POSTGRES:<DBD-POSTGRES-CONNECTION> STRING)) #<DBD.POSTGRES:<DBD-POSTGRES-CONNECTION> {100E99AB73}> "SELECT * FROM \"social_profile\" WHERE (\"service\" = \"github\") ..
 1: ((:METHOD MITO.DB:RETRIEVE-BY-SQL (STRING)) "SELECT * FROM \"social_profile\" WHERE (\"service\" = \"github\") LIMIT 1" :BINDS NIL) [fast-method]
 2: ((SB-PCL::EMF MITO.DB:RETRIEVE-BY-SQL) #<unused argument> #<unused argument> "SELECT * FROM \"social_profile\" WHERE (\"service\" = \"github\") LIMIT 1" :BINDS NIL)
 3: ((:METHOD MITO.DB:RETRIEVE-BY-SQL (SXQL.SQL-TYPE:SQL-STATEMENT)) #<SXQL-STATEMENT: SELECT * FROM "social_profile" WHERE ("service" = "github") LIMIT 1> :BINDS #<unused argument>) [fast-method]
 4: ((SB-PCL::EMF MITO.DB:RETRIEVE-BY-SQL) #<unused argument> #<unused argument> #<SXQL-STATEMENT: SELECT * FROM "social_profile" WHERE ("service" = "github") LIMIT 1>)
 5: (MITO.DAO::SELECT-BY-SQL #<MITO.DAO.TABLE:DAO-TABLE-CLASS WEBLOCKS-AUTH/MODELS::SOCIAL-PROFILE> #<SXQL-STATEMENT: SELECT * FROM "social_profile" WHERE ("service" = "github") LIMIT 1>)
 6: (MITO.DAO:FIND-DAO #<MITO.DAO.TABLE:DAO-TABLE-CLASS WEBLOCKS-AUTH/MODELS::SOCIAL-PROFILE> :SERVICE :GITHUB)
 7: (SB-INT:SIMPLE-EVAL-IN-LEXENV (MITO.DAO:FIND-DAO (QUOTE SOCIAL-PROFILE) :SERVICE :GITHUB) #<NULL-LEXENV>)
 8: (EVAL (MITO.DAO:FIND-DAO (QUOTE SOCIAL-PROFILE) :SERVICE :GITHUB))

I expected Mito will apply deflate automatically, making "GITHUB" string from the :github symbol.

Should this be considered a bug?

fukamachi commented 5 years ago

Thank you for reporting. It looks better to apply deflation.

svetlyak40wt commented 5 years ago

Great! Thank you!