Skip to content

Instantly share code, notes, and snippets.

Avatar

Tomas Mattia tmattia

View GitHub Profile
@tmattia
tmattia / gist:1374045
Created Nov 17, 2011
[RoR] Validate length of relationship
View gist:1374045
$ rails console
Loading development environment (Rails 3.1.1)
ruby-1.9.2-p290 :001 > c = Client.create
SQL (16.3ms) INSERT INTO "clients" ("name") VALUES (?) [["name", nil]]
=> #<Client id: 11, name: nil>
ruby-1.9.2-p290 :002 > 3.times do c.orders.create end
Client Load (0.2ms) SELECT "clients".* FROM "clients" WHERE "clients"."id" = 11 LIMIT 1
Order Load (0.1ms) SELECT "orders".* FROM "orders" WHERE "orders"."client_id" = 11
SQL (0.4ms) INSERT INTO "orders" ("client_id") VALUES (?) [["client_id", 11]]
Client Load (0.2ms) SELECT "clients".* FROM "clients" WHERE "clients"."id" = 11 LIMIT 1
View keybase.md

Keybase proof

I hereby claim:

  • I am tmattia on github.
  • I am tmattiadox (https://keybase.io/tmattiadox) on keybase.
  • I have a public key ASB7KlUumu9HUeX6sRFKVQ9QgOU_2bMOuK8z1ETbZ-NV-Qo

To claim this, I am signing this object: