Questions tagged [has-many-through]

1523 questions
0
votes
1 answer

Undefined Method on has_many :through

I have three models: Class Project < ActiveRecord::Base has_many :tasks has_many :tags, :through => :tasks end Class Tasks < ActiveRecord::Base belongs_to :project has_and_belongs_to_many :tags end Class Tags < ActiveRecord::Base …
0
votes
1 answer

Rails: How to set up an IF condition with a JOIN in a has_many :through relationship

I have an application where users can customize a calendar and fill it with a given pool of events. A user can also overwrite a title for his own calendar by an alias. So I have the following has_many :through relation: class Calendar <…
LeEnno
  • 178
  • 3
  • 13
0
votes
1 answer

Rails has_many through OR query

class Game < ActiveRecord::Base has_many :game_types, :dependent => :destroy has_many :types, :through => :game_types end class Type < ActiveRecord::Base has_many :game_types, :dependent => :destroy has_many :games, :through =>…
0
votes
1 answer

Rails - ActiveRecord - associating a combination of elements to a specific ID

I have an interesting problem that I never had to deal with before. I'm looking for the best way to approach it. I'm creating an admin site linking students to virtual machines. A Student can sign up for multiple courses and has one…
0
votes
3 answers

has_many through: Why do I always need 2 associations for each of the 3 models?

I wonder, why I always have to also specify the has_many :assignments association in both of the models in question when using :through? Is this DRY? Are there cases when I do not need to specify them, or when they differ? Thank you for…
Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152
0
votes
1 answer

Single Table Inheritance or Has Many Through in Rails

I think this is a simple question, but couldn't figure out my exact answer. I have an Event listing that has: People, Food, Costs, To-Do, etc. all as different information items. Instead of having to check each corresponding table if a related data…
dewyze
  • 979
  • 1
  • 7
  • 21
0
votes
1 answer

rails 3.2 update has_many :through

I'm pretty close on this one but caught up on a minor detail. I am trying to update a has_many :through relationship. When I submit the edit form I am unable to extract the appropriate attribute that I want to update. The loop that updates the…
ctilley79
  • 2,151
  • 3
  • 31
  • 64
0
votes
1 answer

Railscasts 258 Token Fields - Set additional attributes in :through table - the rails way to do it

I'm having a problem based on the excellent RailsCast #258 from Ryan Bates. The situation is as follows: class User < ActiveRecord::Base has_many :capabilities, :dependent => :destroy has_many :skills, :through => :capabilities, …
0
votes
1 answer

fields_for for has_many through relationship rails 3

I have problem in getting below code to work. class Page < ActiveRecord::Base has_many :page_parts, :through => :page_parts_pages has_many :page_parts_pages accepts_nested_attributes_for :page_parts, :allow_destroy => true …
0
votes
1 answer

How to model a "checkin" style object in MongoDB?

I am making a new application in MongoDB, and I have found that the Document-oriented modeling style fits all of my models quite well. However, my one stumbling block is a "CheckIn" style action. Users can check in at a location, and I need to…
Sam Stern
  • 24,624
  • 13
  • 93
  • 124
0
votes
1 answer

ActiveRecord has_many :through association through multiple sources

I have a self referencing has_many :through model that has another has_and_belongs_to_many with another model. Basically something like this: class Foo << ActiveRecord::Base has_and_belongs_to_many :bars has_many :foo_links has_many…
Josh Kovach
  • 7,679
  • 3
  • 45
  • 62
0
votes
1 answer

Rails 3 accessing has_many through join model in another controller

I'm doing an online judge application, so I have a User model, a Problem model and a Solution model to make the many to many relation. In that Solution model I have an extra column called "state" where I plan to store the state of a problem for a…
Nocturn
  • 321
  • 6
  • 13
0
votes
2 answers

Rails 3.2 has_many through form submission

I have a has_many :through form where I can't get an extra attribute to post to the database. I'm fouling up the parameter name somewhere. I can get the foreign keys to post but I have another attribute that I'm trying to track in the join table.…
ctilley79
  • 2,151
  • 3
  • 31
  • 64
0
votes
4 answers

select single association from has_many through in Rails

Is there any (clean) way to access a single association when using a has_many through association? For example, to get all of a Recipe's Ingredients, I can write: @ingredients = @recipe.ingredients However, if I have an ingredient already…
0
votes
1 answer

how do I reference and change an extra value in a has many through model

I have Lineup and Piece models joined by piece_lineup model (has many through). I added a 'status' column to the piece_lineup model but i can't figure out how to reference that attribute and/or change it. When listing the pieces associated with a…
Matthew Berman
  • 8,481
  • 10
  • 49
  • 98
1 2 3
99
100