Created
October 3, 2012 12:41
-
-
Save valachi/3826719 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
class Category < ActiveRecord::Base | |
validates :name, presence: true, :uniqueness => true | |
has_many :articles | |
end | |
cLoading development environment (Rails 3.2.8) | |
[1] pry(main)> ct = Category.new(name: '') | |
=> #<Category id: nil, name: "", created_at: nil, updated_at: nil> | |
[2] pry(main)> ct.valid? | |
Category Exists (0.2ms) SELECT 1 AS one FROM `categories` WHERE `categories`.`name` = BINARY '' LIMIT 1 | |
=> false | |
[3] pry(main)> ct = Category.new(name: 'Новости') | |
=> #<Category id: nil, name: "Новости", created_at: nil, updated_at: nil> | |
[4] pry(main)> ct.valid? | |
Category Exists (0.3ms) SELECT 1 AS one FROM `categories` WHERE `categories`.`name` = BINARY 'Новости' LIMIT 1 | |
=> true | |
[5] pry(main)> ct = Category.new(name: Category.first.name) | |
Category Load (0.2ms) SELECT `categories`.* FROM `categories` LIMIT 1 | |
=> #<Category id: nil, name: "Новости", created_at: nil, updated_at: nil> | |
[6] pry(main)> ct.valid? | |
Category Exists (0.3ms) SELECT 1 AS one FROM `categories` WHERE `categories`.`name` = BINARY 'Новости' LIMIT 1 | |
=> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment