Displaying 20 results from an estimated 2000 matches similar to: "Re: validates_associated"
2006 Aug 25
7
acts_as_ferret with conditions
Hello guys,
Having a slight problem with acts_as_ferret, specifically using a
condition. I have the following code
@results = SupplierProduct.find_by_contents(params
[:search], :conditions => [''area_id = ?'', @area])
and it seems the condition isn''t being applied. Does anyone have any
pointers?
Cheers,
Alastair
------
Alastair Moore
Standards compliant web
2005 Dec 19
4
has_one, the = operator and validates_associated
Dear readers,
I am puzzles by the following, imagine models A and B. A has_one B and B
belongs_to A. So far so good. But rails does this great thing by
relfecting on this relationship and enables me use the equals sign to do
A.B=B. But now comes the puzzlement. Whenever you do this B is supposed
to be saved (see,
2006 Jun 12
0
validates_associated -- explicitly setting collection?
Hi, I have a class (say Parent) that has many of two other classes, say
FirstChild and SecondChild. These could look like this:
class Parent < ActiveRecord::Base
has_many :first_children, :dependent => true
has_many :first_children, :dependent => true
validates_associated :first_children
validates_associated :second_children
end
class FirstChild < ActiveRecord::Base
2005 Nov 15
0
validates_associated
I have an db table that associates two things from the same table.
people_alt_people
-----------------
person_id
alt_person_id
So my ActiveRecord looks like:
class PeopleAltPerson < ActiveRecord::Base
belongs_to :person
belongs_to :altperson, :class_name => ''Person'', :foreign_key =>
''alt_person_id''
validates_presence_of :person
2007 Feb 25
0
validates_associated causing weird results
I''d almost think the presence of "validates_associated" is causing the
associated model to run validation twice. The associated model, Upload,
which handles uploaded files and saves them, is saving each uploaded
file twice in a row. This doesn''t happen if I remove
"validates_associated" from the model it belongs to, or if I have the
model save files during
2008 Jun 29
2
How to write test about validates_associated
Here is my model:
class Account < ActiveRecord::Base
has_many :users, :dependent => :destroy
has_many :bus
belongs_to :currency
has_many :mylogs, :dependent => :destroy
has_many :batchuserdefines, :dependent => :destroy
has_many :materialuserdefines, :dependent => :destroy
has_many :materials
has_many :inventories
has_many :batchs
has_many :courses
has_many
2008 Jun 10
2
validates_associated doesn't work on update (and i've tried :on => :update)
HI all-
I have two models, Story and Tag, and they are habtm. My goal is to
show the errors for @story in a form on both new and edit. Everything
works fine on new/create, but it fails on edit/update. First the
models:
class Story < ActiveRecord::Base
attr_accessor :tag_string_holder #holds a CSV of tags
...
has_and_belongs_to_many :tags, :uniq=> true
...
def
2006 Mar 18
1
has_many and validates_associated
By trial and error I seem to arrive to the conclusion that
1. Validation recurses through has_many by default and
a root save! call raises an excepcion if some child no
matter how nested is fails validation
2. Validation does not recurse through has_one by default
and you can change this with validates_associated, in
which case exceptions behave like above
2006 Mar 13
3
validates_associated problem
Hello,
I have a situation where an ''employee'' belongs to a ''department'' and
have setup the relationship as follows.
class Employee < ActiveRecord::Base
belongs_to :department, :foregin_key => "department_id"
validates_associated :department_id
end
class Department < ActiveRecord::Base
has_many :employees
def validate_on_update
2008 Mar 11
1
add_multiple_associated_save_callbacks and validates_associated conflict?
Perhaps I''m misunderstanding what''s happening here, but I''m having a
problem with not being able to disable the validation of an associated
collection if that collection contains a new record. Example...
class Person < ActiveRecord::Base
has_many :email_addresses
validates_associated :email_addresses, :if => Proc.new { false }
end
p = Person.new
2007 Mar 30
0
Rolling up validates_associated error messages into parent
All,
I really dig using validates_associated on my models to automatically
validate their associated objects.
However, I find that I would prefer that the associated object''s error
messages were propagated up to the original (object on which validate
was called) object as they are, instead of the original object showing
"X is invalid" where X is one of the associated objects.
2007 Oct 22
1
installing rspec/rspec_on_rails as system wide generator (or similar)
Hi all,
What would be the best/easiest way of installing rspec as a system
wide generator so I''m not having to download it or ./script/plugin
install it every time?
Thanks,
Alastair
-----
Alastair Moore
Freelance web design, development and consultancy
t. 07983 983945
e. alastair at kozmo.co.uk
w. http://www.kozmo.co.uk
skype. alastair_kozmo
2006 Jun 13
6
Dead horse: validates_associated
Regarding validates_associated...
Let''s say I have:
article belongs_to author
But for whatever reason, I want an article to also be written
anonymously and therefore not require an author. Then I have:
Article:
belongs_to :author
validates_associated :author
But I DON''T have validates_presence_of. What I want to do is validate
that an author is valid --if it is
2007 Oct 10
9
Rspec Textmate bundle errors
Hello all,
Having a problem with the Rspec textmate bundle and having quizzed
the guys in #textmate to no success about the errors, I''ve been
suggested to try you guys!
When I run the "Run Behaviour Description" command, I get the
following errors:
/Users/alastair/Library/Application Support/TextMate/Bundles/
RSpec.tmbundle/Support/lib/spec/../spec/mate/runner.rb:34:in
2006 Aug 26
3
order of saving/validating
Hi guys,
I''m trying to do some validation on an image upload. Basically I have
a model, Property, which has_many :property_images. I need to check
that one image has been uploaded at least and so it was suggested I
checked the number of images uploaded -
@property.property_images.count > 0. Makes sense.
I''ve added a validation on my Property model, like -
def
2005 Oct 26
2
validates_associated ... doesn't
Hi,
I think I''m missing some fundamental information here so hopefully
someone can help me. I have a model Club which has many members,
members of course belong to a Club. I''d like to ensure that when a
members is saved (saved/created/updated) only valid club_id''s are accepted.
I have a Club model (simplified) like this:
class Club < ActiveRecord::Base
2006 Apr 26
1
Bug in validates_associated?
Here is the setup:
Windows XP, InstantRails, MySQL 14.7, Ruby 1.8.4, Rails 1.1.2
MODEL:
class Office<ActiveRecord::Base
has_many :users
end
class User<ActiveRecord::Base
belongs_to :office
validates_presence_of :office_id
validates_associated :office
<....other stuff...>
end
UNIT_TEST test/unit/user_test.rb
def test_associations
u = User.new
u.office_id =
2013 Feb 13
3
conditional validates_associated
Hello,
Have you guys noticed that conditional validation with validates_associated
does not work well when you are creating a new record?
Consider this gist: https://gist.github.com/aflag/4780225
The Lawyer class has validates_associated on address conditioned on whether
the Lawyer data comes from a known source or not. So, if lawyer.source
equals to some string, then lawyer.address must
2006 Mar 14
0
validates_associated stops after first fail
Hi,
I am using validates_associated to validate some child models. The
validation of the children stops after the first failed validation. i
would like to validate all the children so that errors for more than
one can be displayed in a form. Is there a way to do this without
looping through all the children?
Thanks,
Peter
2006 Feb 03
0
validates_associated questions
I''m trying to validate a User model object that belongs_to a company
class User < ActiveRecord::Base
belongs_to :company
validates_associated :company, :message=>"Company can not be blank"
end
Now, if my Company class has the following:
validates_presence_of :name
shouldn''t that result in the error message beign added to the error
messages for the user??