Il 17 giugno 2012 10:17, Tommaso V. [email protected]
ha scritto:
mi sa che mi sta sfuggendo qualcosa
Ciao,
ho appena provato con un’applicazione rails pulita, con:
class Person < ActiveRecord::Base
attr_accessible :name, :surname
validates :name, :uniqueness => true
end
E funziona senza problemi:
1.9.3p194 :001 > Person.create :name => ‘Joelle’, :surname => ‘Smith’
SQL (1.0ms) BEGIN
Person Exists (0.4ms) SELECT 1 FROM people
WHERE people
.name
= BINARY ‘Joelle’ LIMIT 1
SQL (1.3ms) INSERT INTO people
(created_at
, name
, surname
,
updated_at
) VALUES (?, ?, ?, ?) [[“created_at”, Sun, 17 Jun 2012
09:32:50 UTC +00:00], [“name”, “Joelle”], [“surname”, “Smith”],
[“updated_at”, Sun, 17 Jun 2012 09:32:50 UTC +00:00]]
(29.1ms) COMMIT
=> #<Person id: 1, name: “Joelle”, surname: “Smith”, created_at:
“2012-06-17 09:32:50”, updated_at: “2012-06-17 09:32:50”>
1.9.3p194 :002 > Person.create :name => ‘Jolle’, :surname => ‘Smith’
SQL (0.1ms) BEGIN
Person Exists (0.4ms) SELECT 1 FROM people
WHERE people
.name
= BINARY ‘Jolle’ LIMIT 1
SQL (0.7ms) INSERT INTO people
(created_at
, name
, surname
,
updated_at
) VALUES (?, ?, ?, ?) [[“created_at”, Sun, 17 Jun 2012
09:32:58 UTC +00:00], [“name”, “Jolle”], [“surname”, “Smith”],
[“updated_at”, Sun, 17 Jun 2012 09:32:58 UTC +00:00]]
(25.0ms) COMMIT
=> #<Person id: 2, name: “Jolle”, surname: “Smith”, created_at:
“2012-06-17 09:32:58”, updated_at: “2012-06-17 09:32:58”>
1.9.3p194 :003 > Person.create :name => ‘Jolle’, :surname => ‘Smith’
SQL (0.1ms) BEGIN
Person Exists (0.4ms) SELECT 1 FROM people
WHERE people
.name
= BINARY ‘Jolle’ LIMIT 1
(0.1ms) ROLLBACK
=> #<Person id: nil, name: “Jolle”, surname: “Smith”, created_at:
nil, updated_at: nil>
Guarda in development.log, come sono le query per verificare l’univocit.
pietro