Displaying 20 results from an estimated 4000 matches similar to: "validates_uniqueness_of on has_and_belongs_to_many"
2005 Aug 19
2
data validation
I''m trying validate date before they''re stored into the DB, but it seems,
validation doesn''t work..
my model looks like this:
class Company < ActiveRecord::Base
has_many :contacts,
:foreign_key =>''company_id''
has_and_belongs_to_many :categories, :join_table => ''company_to_category'',
:foreign_key =>
2006 Jul 12
1
odd habtm behavior? or is it me?
Hello List,
I''m a bit spent on this problem, and my code might be whack. I seem to be
encountering a problem where the primary key on a join table is not being
resolved correctly. I will elaborate after some code bits. I am creating
the join table using migrations, and relevant model code is this:
class Post < ActiveRecord::Base
has_and_belongs_to_many :records
2006 Apr 05
2
validates_uniqueness_of with habtm
it''s a blog...
class Entry < ActiveRecord::Base
has_and_belongs_to_many :categories
end
similarly:
class Category < ActiveRecord::Base
has_and_belongs_to_many :entries
end
I wish to make sure that the owner doesn''t add the same category to a
given entry more than once... I''m thinking that validates_uniqueness_of
should be usable here. But can''t
2006 Apr 09
1
select helper question
Hi there, I try to develop a medical application using ruby on rails.
There are many categories which can contain subcategories.
I defined the model like this:
class Category < ActiveRecord::Base
has_and_belongs_to_many :notes
belongs_to :parent_category, :class_name=>"Category",
:foreign_key=>"category_id"
has_many :sub_categories,
2006 May 23
7
has_and_belongs_to_many question
Hello,
I am trying to make the "switchover" to programming my apps in Rails and
have a question about database structure.
In the past i would structure a many to many like this:
categories
----------------------------------------------------
| id | name |
----------------------------------------------------
1 Some Category
2 Another
2006 May 10
4
validates_uniqueness_of and create atomicity
Hi folks,
I have a question regarding validates_uniqueness_of, and similar
before-filter-like events attempting to guarantee some DB state prior
to modification.
>From my reading of ActiveRecord, validate_uniqueness_of appears to
cause a SELECT on the underlying table attempting to ensure that a
record with ID(s) specified in the validates_uniqueness_of statement
is not already present, prior
2006 Jul 07
0
has_many relation handling
Hello,
please have a look at this:
My tables:
create_table :languages do |t|
t.column :name, :string, :limit => 3
t.column :title, :string, :limit => 30
end
create_table :categories do |t|
t.column :category_id, :integer (3.)
t.column :created_at, :timestamp
t.column :updated_at, :timestamp
end
create_table :categorytranslations, :id
2006 Jan 16
0
belongs_to with has_and_belongs_to_many
I''m having a problem with belongs_to and has_and_belongs_to_many.
Here''s a brief summary of the models involved:
class Member < ActiveRecord::Base
set_primary_key ''member_id''
has_and_belongs_to_many :projects, :join_table => ''projects__members''
has_many :projects, :foreign_key => ''created_by''
end
class
2006 Aug 10
2
validates_uniqueness_of problem
hi
Could I check to strings for uniqueness together and not individually?
That means for me in an example:
name: sex: result:
----- ---- -------
miller m unique
miller f unique
jackson m unique
miller m isn''t unique
So I want to check the name and sex be together unique. The name isn''t
2006 Mar 23
2
rails 1.1 and mysql errors
Hi,
I just upgraded to rails 1.1 this morning and i am getting a variety of
errors from tests that were passing effortlessly on the previous edge
release (i froze several weeks ago, so I not sure what version that was).
Has anyone else experienced these types errors with the new rails:
I have several errors that are grouped around create and destroy commands
the errors are similar, first the
2006 Jul 28
0
Dreamhost, fastcgi, validates_uniqueness_of.... is not always unique?
Hey everyone,
I have an application running on dreamhost with fast cgi (FCGI). I have a
model, "Member", that has the following validation:
validates_uniqueness_of :email, :if =>
Proc.new{|member| !member.email.blank?}
The :if clause is really not needed because an email address is required and
in fact the model also has:
validates_presence_of :email
2008 Sep 19
0
validates_uniqueness_of: passing a method to :scope
I was wondering if anybody knows an easy way to pass a method name as
the scope option to a validates_uniqueness_of validation on a AR model?
For example, I have nested models a bit like:
class Survey
has_many :areas
end
class Area
belongs_to :survey
has_many :questions, :order => ''position''
validates_uniqueness_of :position, :scope => : survey_id
end
class
2006 May 10
1
Validates_uniqueness_of multiple field combo?
Hello,
I am new to Ruby on rails and this is therefore probably trivial. Lets
say I have 3 tables - users[id,name, age, ...],
interests[id,name,description, ...], and finally a table
user_interests[id,user_id,interest_id] to link a user to a set of
interests. Now there is no problem to put validates_uniqueness_of :name
in the user-model to ensure that I only have one Lenny, but how do I
2006 Sep 11
0
validates_uniqueness_of :number by the year in a DateTime column
Hello all,
I have a class Ticket < ActiveRecord::Base which has a property called
:number and a property called :samples_date.
a ticket number has to be unique over the same year. the year is given
by the property called :samples_date
I''m trying to validate the uniqueness of :number based on the year from
the :samples_date property.
i would like to specify the condition somehow in
2009 Jun 26
0
validates_uniqueness_of and MySQL enum type
I tried to check validates_uniqueness_of for a MySql enum type column
with a scope given, like this:
validates_uniqueness_of :phone_type, :scope => :user_id
And It didn''t work. When I check the SQL statement for doing this
validation, it is like this:
SELECT `phone_numbers`.id FROM `phone_numbers` WHERE
(`phone_numbers`.`phone_type` = BINARY '''' AND
2009 Oct 02
0
Problems with validates_uniqueness_of
Hi to everybody, well i recently became a RoR developer, web i was
following the video class from Lynda, and i introduce more code in my
aplicacion, my application is a music store web site, ok so i add the
funcionality of add clients, for that i need from my client, his user
and password, so it will be 1 user per client, for that reason i use at
my model
validates_uniqueness_of :user
2007 Jul 30
3
validates_uniqueness_of doesn't work if value tested is numeric and column is string
Hello all,
I am working through the depot example in the rails book. If I add a
validates_uniqueness_of to a string column in the model, and then try
to create a record with a number in this string column I get an SQL
error. Looks like the SQL generated to test for uniqueness does not
quote the value if it''s numeric even though it''s comparing against a
varchar column. It does
2007 Aug 30
3
has/belongs to many sql error
I have a model Asset which has_and_belongs_to_many :tags. Tag has only
one field, name. There is a table assets_tags which only has an
asset_id and a tag_id.
I can add a tag to one asset. If I try to add the same tag to another
asset though (asset.tags << tag) I get this error:
Mysql::Error: #23000Duplicate entry ''4'' for key 1: INSERT INTO
assets_tags (`tag_id`, `id`,
2006 May 18
1
validates_uniqueness_of
I used validates_uniqueness_of
it is case insensitive, it takes only admin not Admin.
So please help me out how to put validates_uniqueness_of as case
sensitive
Thanks in Advance
Surekha.Matte
--
Posted via http://www.ruby-forum.com/.
2010 Mar 21
0
Validates uniqueness scope
In a Rails 2.x validation to check if the name of some model is unique
within a some category, I would use:
`validates_uniqueness_of :name, :scope => :category_id`
In Rails 3, this is replaced with:
`validates :name, :uniqueness => true`
However, I can''t seem to find a method of defining the uniqueness''
scope. Am I missing something?
Thanks,
Angelo
--
You received