Created
October 9, 2012 16:28
-
-
Save solnic/3859885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* generated */ | |
| SELECT "user_id", "username", "id", "street" FROM (SELECT "id" AS "user_id", "username" FROM "users") AS "left" NATURAL JOIN "addresses" AS "right" | |
| /* inner join alternative */ | |
| SELECT users.id AS user_id, username, addresses.id, street FROM users INNER JOIN addresses ON users.id = addresses.user_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| include Veritas | |
| users = Relation::Base.new :users, [ Attribute::Integer.new(:id, :key => true), Attribute::String.new(:name) ] | |
| addresses = Relation::Base.new :addresses, [ Attribute::Integer.new(:id, :key => true), Attribute::Integer.new(:user_id), Attribute::String.new(:street) ] | |
| relation = users.rename(:id => :user_id).join(addresses) | |
| SQL::Generator::Relation.visit(relation).to_sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment