Hey guys,
I have a simple model "Match" that is supposed to save the bi-directional link between two objects (of the same kind).
class Match < ActiveRecord::Base
belongs_to :obj1, :class_name => "MyModel", :foreign_key => :obj1_id
belongs_to :obj2, :class_name => "MyModel", :foreign_key => :obj2_id
...
end
The problem I have is...
The uniqueness validator of ActiveRecord has an options to skip validation if the value is nil or blank. Even if I set both parameters to true (the default behaviour) I can create one record with nil and blank before the validation hits. I use the default SQlite3 Database sqlite3-ruby (1.2.5).
Edit for clarification: I get the expected ...
I have a Rails model that should only allow saving/updating of a model once per day per user. I have a callback to do the Find by user and date then add to errors but this is ugly and feels un-rails-like. I have the typical created_at / updated_at columns (and the time portion is significant/I need to keep it).
So I figure I could eithe...
I have Labellings which belong to Emails and Labels.
Each labelling must be unique to the email/label pair - so an email can only be labelled 'test' once.
I'm doing this with validates_uniqueness_of :label_id, :scope => :email_id. This works as expected.
When I am labelling emails, I want to add the labelling if it is unique, and do n...
I have a model that has two fields, which I will call first_name and last_name, and I want to make sure that the combination of the two are case-insensitively unique. I've gotten halfway there by using this:
validates_uniqueness_of :first_name, :scope => :last_name
The problem is that the uniqueness check seems to be case sensitive, e...
Hi everyone,
Is there any way I can validate a value updated in a Core Data entity's property against values of the property in other entities in the collection?
At the moment I create an entity with some default values, add it to arrangedObjects, then get the user to modify the various property values. However, I would like to check a...
In Rails 2.x you can use validations to make sure you have a unique combined value like this:
validates_uniqueness_of :husband, :scope => :wife
In the corresponding migration it could look like this:
add_index :family, [:husband, :wife], :unique => true
This would make sure the husband/wife combination is unique in the database. No...
I have a Project model which accepts nested attributes for Task.
class Project < ActiveRecord::Base
has_many :tasks
accepts_nested_attributes_for
:tasks, :allow_destroy => :true
end
class Task < ActiveRecord::Base
validates_uniqueness_of :name end
Uniqueness validation in Task model gives problem while updating...
can i have a validation which do exactly opposite to validates_uniqueness_of? i.e. i would like to show a error message when the user input is NOT exist in database.
thanks all. :)
...
I have the following in my migration file
def self.up
create_table :payment_agreements do |t|
t.boolean :automatic, :default => true, :null => false
t.string :payment_trigger_on_order
t.references :supplier
t.references :seller
t.references :product
t.timestamps
end
end
I want to ...
After changing the @id of a Entity from
@Id
private int getId(){
return this.id;
}
to
@Id
private String getLogin(){
return this.login;
}
I get the error:
a different object with the same identifier
value was already associated with the session
In the webapplication isn't changed anything. A read the entity and then ch...
It's not some kind of synchronization problem I readed before.
The code is quite simple.
The model:
class User < ActiveRecord::Base
attr_accessor :name, :email
validates_uniqueness_of :email, :on => :create, :message => "must be unique"
end
The rspec test:
require 'spec_helper'
describe User do
before(:each) do
@v...