search for: has_many_through

Displaying 8 results from an estimated 8 matches for "has_many_through".

2006 Apr 08
4
saving related objects using has_many_through associations
This only saves the @person but not the @address. Shouldn''t it save both? @person = Person.new(params[:person]) @address = Address.new(params[:address]) @person.address << @address @person.save here is what I have: class Person < ActiveRecord::Base has_many :addressables has_many :addresses, :through => :addressables end class Address <
2012 Apr 03
4
one master table to hold symbols: good or bad idea?
(This is may be more of a db design question than a rails question.) Summary: I''m thinking of creating a single AR class to hold constant symbol values and use it for :has_many_through relations whenever I need a constant symbol. Is this a good idea or a bad idea? Details: I notice that I have a lot of models that contain just a name string: create_table "natural_resources", :force => true do |t| t.string "name" end create_table "roles...
2010 Oct 14
2
Nested form, perhaps?
...ement system. A new project needs a team to work on it. The project has been saved, so we don''t have to worry about that. But each member of the team needs to have a role in relation to this project (they may have another role on a different project). So I am thinking about using a has_many_through relationship between projects and people using a Role model. An admin comes to a new screen to set up the team for this project. She sees a list of all available people in the system, and can check one or more of them to be added to the team. In each chosen person''s form row, she...
2006 Jul 10
18
Deleting join association of has_many :through
I''m trying to use has_many :through, since my join model deserves being more than just an intersection table. But when I try to break the association, the break only seems "temporary": Let''s say my two tables are Users and Colors, and the join model is Favorites. user = Users.find(1) user.colors.length >> 2 c = user.colors.first >> #<Color:....>
2007 Dec 06
0
has_many :through with a has_one source
Here is my simple example... require ''rubygems'' require ''active_record'' ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => "has_many_through.db" ActiveRecord::Schema.define do create_table "containers", :force => true do |t| t.column :name, :string end create_table "shapes", :force => true do |t| t.column :name, :string t.column :container_id, :integer end create_table "colors&...
2008 Jan 30
0
Plugin belongs_to Model Association Bug
...ot; error. If I check what kind of class @post.user is, Ruby will report it is a "User" class. I have tried to hack around this by doing a "def user { User.find(user_id) }" in the plugin, but users are used as associations in numerous instances in numerous models, sometimes as has_many_throughs, so besides being ugly, I don''t think this hack is going to be viable across the board (though doing a User.find of the user_id does return a model with methods intact). Do any of you have any suggestions about how I could fix (or start to debug) this issue? Thanks, Bill Harding --~--~-...
2006 Nov 06
21
acts_as_ferret and associations
I have the following models: class Book < ActiveRecord::Base acts_as_ferret belongs_to :author end class Author < ActiveRecord::Base has_many :books end and in the controller: def search if params[:query] @query = params[:query] @total, @books = Book.full_text_search(@query, :page => (params[:page]||1)) @pages =
2013 Mar 24
5
Rails 4.0 has_many_through and fields_for
Hi all, I am trying to reproduce rails 3.2 behaviour with fields_for and nested attributes. class ControllerAction < ActiveRecord::Base has_many :interactions, dependent: :destroy has_many :roles, through: :interactions scope :controllers, lambda {|name| where("controller_name_id = ?", name)} scope :actions, lambda {|name| where("action_name_id =