Displaying 20 results from an estimated 20000 matches similar to: "Nested forms and deleting/removing has_many associations"
2009 May 27
0
Nested Forms with has_many associations with validations
I want to have a parent model that I can add child objects (via a
has_many association) using the rails 2.3 nested form syntax. However,
it seems like rails throws an error during validation of the parent
model if I have a validates_presence_of :parent_id defined in the child
model.
Is the only solution to this to remove the validates_presence_of
:parent_id? This seems like a hack-ish workaround.
2006 Feb 03
1
nested has_many associations
My question is whether the rails helper methods for handling associations can
be nested (see examples below). I suspect not as currently I''m
getting "unknown method" if I try and use two associations in one call.
The essence of the code is
class User << ActiveRecord::Base
has_many :items
class Items << ActiveRecord::Base
has_many :reservations
belongs_to
2009 Mar 13
1
Problem saving nested attributes for has_many associations (Rails 2.3 RC2 and Edge)
I''ve tested this on both 2.3 RC2 and Edge. This pastie contains
model, helper and view: http://pastie.org/415742
When I save a vocabulary - its terms don''t save. I''m fairly sure it
worked in RC1. Would appreciate any insight.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on
2009 Apr 12
0
rails 2.3 nested forms with has_many through checkboxes
I was wondering if anyone knew of a way to combine the new nested
forms in rails 2.3 with a has_many through relationship via
checkboxes. Basically I have a page model, a page_category model and
a category_items join table. Pages have many page categories through
category items. The category_items table is polymorphic so i can use
it for other models who need categories (maybe this is
2009 Feb 26
0
Using form_for and has_many associations with a controller in its own subdirectory
Hi,
I''m trying to create a Blog in it''s own subdirectory for an E-commerce
site. Everything is hooked up just fine for the basic posting, but
when I try to add Comments, I''m getting all sorts of headaches! I''m
referring to the screencast by Ryan Bates on the rubyonrails.org site.
Basically, my controller is Blog::Comments, in my Blog::Post comment
form I have
2010 Feb 06
1
accepts_nested_attributes_for with has_many => :through
I have two models, links and tags, associated through a 3rd model,
link_tags. I added the following to my link model,
has_many :tags, :through => :link_tags
has_many :link_tags
accepts_nested_attributes_for :tags, :allow_destroy => :false,
:reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
and put this in a partial called by the new and edit forms for links,
2006 Mar 24
2
Change to has_many :through associations
Hi everyone. I''ve made a default change to has_many :through
associations that I felt was important to make before they''re
released. This is after some tickets and confusion I''ve seen
regarding has_many :through.
class Connection < ActiveRecord::Base
belongs_to :user
belongs_to :channel
end
class Channel < ActiveRecord::Base
has_many :connections
2006 Apr 04
1
Manipulating has_many :through associations
Hi,
I haven''t done any associations before, so please forgive my incorrect
use of terminology...
If I set up a has_many :through association, can I manipulate the
associated instances directly (like an Array), or do I need to
manipulate the join model?
For example, suppose I have two classes and the associated join model:
class foo
has_many :foo_bars
has_many :bars, :through
2006 Aug 16
1
Naming rights_roles join model using has_many :through and polymorphic associations
Hi.
I have a couple of best practices questions regarding polymorphic
associations, naming join tables and user permissions.
Currently I have implemented the user authentication model from the
rails recipes book. Basically it goes something like this:
MODEL CLASSES:
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
end
class Role < ActiveRecord::Base
2011 Jul 26
1
ActiveRecord has_many associations
Given the models Country, State, City and Person as follows.
class Country < ActiveRecord::Base
has_many :states
end
class State < ActiveRecord::Base
belongs_to :country
has_many :cities
end
class City < ActiveRecord::Base
belongs_to :state
has_many :people
end
class Person < ActiveRecord::Base
belongs_to :city
end
Is there any way that doesn''t allow to delete
2006 Jun 13
0
question about saving associations when using has_many :through
I''ve got a User model and a Book model. A user is required to submit
books each month to be reviewed by other users. I have the following
relationships defined:
# the join model
book_review.rb
belongs_to :user
belongs_to :book
end
book.rb
# each book is reviewed by many users. This allows us to get the BookReview
# objects associated with this book
has_many :book_reviews,
2009 Jan 22
0
ActiveLdap belongs_to and has_many associations
Hi,
I am trying to use ActiveLdap for authentication in my rails app. But I
am running into a problem with the "belongs_to" and "has_many"
associations.
Here ist how my models look like.
class Person < ActiveLdap::Base
ldap_mapping :dn_attribute => "uid",
:prefix => "ou=People",
:classes =>
2006 Aug 17
0
Editiing multiple has_many associations at once
I am search for a nice tidy solution to the following or if only to talk
the problem out aloud.
I have three tables
products
has_many :pricings
pricings
belongs_to :product
belongs_to :pricing_group
pricing_groups
had_many :pricings
I would like to have a single page where I can add/edit a product and on
the same page administer the pricing for that product for each pricing
group.
2006 Sep 03
1
New Technique: Subsets of has_many Associations
I just now thought of this, and sure enough it works like a charm (at
least so far in my limited testing):
has_many :events, :dependent => :delete_all
has_many :upcoming_events, :class_name => "Event", :conditions =>
"date > NOW()"
The purpose of this is that it makes eager loading of subsets of
associations possible without replacing all the magic of the
2006 Jul 24
1
problem with has_many associations
Hi all,
I have some problems with a few temporary objects, this is the relation
between them:
A -(1,n)-> B -(1,1)-> C
B -(1,n)-> D
C -(1,n)-> D
I have a "wizard" to create "A" objects, I''m storing everything in the
session, something like this:
a = A.new
session[:a_object] = a
...
b = B.new
b.c = some_c_instace
a.bs << b
...
d = D.new
b.ds
2006 Jan 30
0
Serializing has_many associations and ActiveRecord objects
Is it possible to serialize ActiveRecord objects and ActiveRecord
children to XML?
--
Posted via http://www.ruby-forum.com/.
2008 Apr 24
2
Dynamic finders in has_many associations
I have these 3 models.
class Ivr < ActiveRecord::Base
has_many :klusterings, :dependent => :destroy
has_many :klusters, :through => :klusterings, :uniq => true
end
class Kluster < ActiveRecord::Base
has_many :klusterings, :dependent => :destroy
has_many :ivrs, :through => :klusterings, :uniq => true
end
class Klustering < ActiveRecord::Base
belongs_to :kluster
2012 Aug 13
10
Question about PATCH method, accepts_nested_attributes_for, and updates to association lists (has_many, HABTM)
Am interested in the new PATCH method that will be included in Rails 4, but
have a question/concern, and forgive me if I''m misunderstanding it.
So, if the request parameter _method is set to "patch", the update is
processed as a patch.
But, let''s say you have a model called Airplane and Airplane has a
collection of FlightCrewMembers which it
2010 Jun 17
0
Edge Rails Nested has_many :through Association
So this functionality isn''t supported natively in Rails 3 (or any
versions before that for that matter) But I had found a work around
via this blog post: http://geoff.evason.name/2010/04/23/nested-has_many-through-in-rails-or-how-to-do-a-3-table-join/
This didn''t work on Rails 3 because it wasn''t able to properly build
the query from the join with symbols. I was
2008 Apr 11
2
Validating an ActiveRecord object and its has_many :through associations
Considering an object with several has_many :through => associations,
what is the ''best'' way to handle validations?
As an example:
class Student < ActiveRecord::Base
# some attrbutes like
# :name
# :grade
# relationships
has_many :students_assignment, :dependent => :destroy
has_many :assignments, :through => :students_assignment
has_many