similar to: prevent orphan records

Displaying 20 results from an estimated 10000 matches similar to: "prevent orphan records"

2009 Nov 20
3
Ensuring that foreign key is valid
I am trying to set up a validation in a model to ensure that a record can''t be saved unless the foreign key it belongs_to is a valid record. My model says: class Admin < ActiveRecord::Base validates_presence_of :user_id validates_numericality_of :user_id validates_uniqueness_of :user_id validates_associated :user belongs_to :user end but I can still create an admin
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 Jun 21
1
Validation Through Multiple Models from one Form
Hey All, I have a form that submits data to multiple models. I have class Man < ActiveRecord::Base has_many :notes has_many :contacts validates_associated :contacts, :notes validates_presence_of :first_name validates_presence_of :last_name class Contact < ActiveRecord::Base belongs_to :man validates_presence_of :contact_info class Note < ActiveRecord::Base
2009 Jul 04
12
save! not allowed after validates_uniqueness
I have this in a model validates_uniqueness_of :aspect, :scope => :user_id In an instance method of the same model I have "save!" but I don''t touch the :aspect attribute in that instance method at all. Whenever that save! command is run however I get this error: ActiveRecord::RecordInvalid: Validation failed: Aspect has already been taken I don''t
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 Jul 01
6
validates_associated & foreign keys
Hi, I''m struggling to get the validates_associated to work as I think it should be. I''m using: JRuby 1.1 rails-2.0.2 activerecord-2.0.2 activerecord-jdbc-adapter-0.8.2 My tables in MySQL: CREATE TABLE area_codes ( id INT UNSIGNED auto_increment primary key ... ); CREATE TABLE markets ( id INT UNSIGNED auto_increment primary key, ... ); CREATE TABLE
2006 Jul 27
9
Introspecting validates_presence_of
Hello people, I''d like to detect whether an attribute of a model has vaildates_presence_of applied to it so I can automatically apply a mandatory (*) to the field...it doesn''t look easy...any ideas? Cheers, -- Dan Webb http://www.danwebb.net
2006 Jan 03
4
validates_presence_of *_id attributes
Hi all, I am a newbie to Rails. Please enlighten me on how to do this appropriately, the Rails and the Ruby way: Suppose I have a Recipe model. Let''s simplify things and pretend that it has only 2 attributes, a :name and the other is a ''category_id''. In the recipes table, category_id is a foreign key to field id of table categories. We also assume that I have generate
2006 Apr 27
3
Removing a default value for a foreign key with not null set
Hi all, For various reasons I need to have foreign keys with not null constraints. Eg: create_table :people do |t| t.column :name, :string t.column :household_id, :integer, :null => false end create_table :households do |t| t.column :name, :string end add_foreign_key_constraint :people, :household_id, :households, :id So the people table has a foreign key into
2006 Jan 11
7
Create a relationship with 2 or more tables on 1 insert
userstable: |id|name|password| userdetailstable: |id|col1|col2|col3|user_id| this is my code: [code] def create @user = User.new(@params[''user'']) @userdetail = Userdetail.new(@params[''userdetail'']) if @user.save and @userdetail.save flash[:notice] = "Save succeeded..." redirect_to :action => ''list''
2006 Oct 14
2
issues with validates_associated not throwing error
Hello all I''m having an issue with ruby on rails, and it not throwing an error where it should. I have a class ''clientpool'' that is: class Clientpool < ActiveRecord::Base set_table_name "clientpool" set_primary_key "id" belongs_to :clients, :foreign_key => "cliname" validates_presence_of :cliname validates_associated :client end
2005 Dec 16
4
Validation with Aggregation
ActiveRecord supports composed_of for value objects which is fantastic but one thing that it doesn''t seem to support (or at least I am unable to find any documentation for) validation of the value objects. For example, given the following: class Message < ActiveRecord::Base composed_of :sender, :class_name => ''EmailAddress'' composed_of :recipient,
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
2010 Jun 08
9
[Rails Heroku] Problem with saving object (on heroku hosting)
Hi All, I have some strange problem which appears only on heroku hosting 2.3.5 default stack (not on my local computer) I have some models. Here they are: class Contact < ActiveRecord::Base belongs_to :user belongs_to :type, :class_name => "ContactType", :foreign_key => "type_id" validates_presence_of :name, :on => :create, :message =>
2006 Jul 22
7
Validation with has_many
I have two problems. I have a comment that has_many uploads. Before saving the comment, I want to be sure that the upload(s) has passed validation, but I also need to validate in other ways. For example, I do not want to save the comment if there is no comment or upload. Or, I do not want to save the comment if the image has been uploaded previously (comparing md5s with past upload md5s
2007 Jan 01
5
Validations based on associations
My model is very simple, it''s mostly just a join table that represents which tournaments a user has registered for. class Registration < ActiveRecord::Base belongs_to :user belongs_to :tournament validates_presence_of :user_id, :tournament_id validates_uniqueness_of :user_id, :scope => :tournament_id end the validates_uniqueness checks to make sure there''s no
2005 Oct 12
4
Validating 2 related models at once not working
Hello, I have a form that submits data to two related models/tables. One is Customer the other is Address. Validation for Customer works fine but not for the Address. Class Customer < ActiveRecord::Base has_one :address validates_presence_of :login, :password, :email validates_associated :address end Class Address < ActiveRecord::Base belongs_to :customer validates_presence_of
2006 Jul 12
5
validates_peresence_of
Is there an expert validater that can point me in the right direction? I''ve looked for extended documentation on ''validates_presence_of'' but i can''t seem to find any. I''m trying to make sure that i don''t enter a nil object in my database, so i''ve added validate_presence_of to my Record Model. i.e. --> class Record <
2005 Dec 29
3
Verification problems
Hello, Hope this isn''t a newbie question - but I don''t seem to be able to find relevent information elsewhere. I am having trouble getting the following to work: Schema ====== ActiveRecord::Schema.define(:version => 1) do create_table "authors", :force => true do |t| t.column "name", :string end create_table "books", :force =>
2006 May 28
3
Validating Foreign Key
Howdy, I''m a Rails beginner working on my first significant project with RoR. I''m trying to figure out how to validate a foreign key (you know, make sure the row actually exists.) However, validates_associated doesn''t seem to be what I want to use, nor does it work... -- BEGIN -- class City < ActiveRecord::Base has_many :schools belongs_to :state