On Tuesday, January 14, 2014 4:26:00 AM UTC-8, Christoph Haas wrote:
>
> Dear list,
>
> feel free to call me "stupid" and make this "wontfix". I just stumbled
> upon a weird problem and it took me a while to find the cause.
>
> Wrong:
> class VirtualDomain < Sequel::Model
> one_to_many :virtual_users, :key => 'domain_id'
> …
>
> Right:
> class VirtualDomain < Sequel::Model
> one_to_many :virtual_users, :key => :domain_id
> …
>
> I know that the documentation says to use symbols like :domain_id and
> not strings like 'domain_id'. If strings should not be used I would
> appreciate to get warned about that. Because what happens (in MySQL)
> when you use a string is:
>
> SELECT * FROM `virtual_users` WHERE ('domain_id' = 1);
> => Empty set
>
> Using symbols it issues the correct query:
>
> SELECT * FROM `virtual_users` WHERE (domain_id = 1);
> => Rows…
>
> Just wondering if it's worth to make Sequel complain it or magically use
> the right SQL anyway.
>
This is expected. In Sequel, ruby symbols represent SQL identifiers, and
ruby strings represent SQL strings. Once you understand that principle,
it's simple to determine which to use. I don't plan on modifying Sequel to
try to determine where a string is used but a symbol may have been meant.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.