Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for string foreign keys #5

Open
donut opened this issue Oct 9, 2017 · 2 comments
Open

Support for string foreign keys #5

donut opened this issue Oct 9, 2017 · 2 comments

Comments

@donut
Copy link

donut commented Oct 9, 2017

I have a table with a primary key that is of type VARCHAR and is referenced by another table, but it looks like Sequoia only supports. At least, when I try to compile I get this:

Error: This expression has type
         string Alias.Field.t = (Alias.Field.table, string) Sequoia_field.t
       but an expression was expected of type
         (Alias.Field.table, int) Sequoia_mysql.M.Field.t =
           (Alias.Field.table, int) Sequoia_field.t
       Type string is not compatible with type int

Example:

open Sequoia_mysql

module URL = struct
  include (val table "url")
  let id = Field.int "id"
  (* ... *)
end

module Alias = struct
  include (val table "alias")
  let name = Field.string "name"
  let url = Field.foreign_key "url" ~references:URL.id
  (* ... *)
end

module Use = struct
  include (val table "use")
  let id = Field.int "id"
  let alias = Field.foreign_key "alias" ~references:Alias.name (* <- error *)
  let url = Field.foreign_key "url" ~references:URL.id
  (* ... *)
end
@andrenth
Copy link
Owner

This is sort of by design, as I believe non-integer foreign keys are not considered a good practice. I could be convinced otherwise, but one of the goals of Sequoia is to try to enforce good practices.

@donut
Copy link
Author

donut commented Oct 11, 2017

While I'm not 100% convinced in general, I have been convinced for my project that non-integer foreign keys are not the best idea. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants