Questions tagged [has-many-through]
1523 questions
0
votes
1 answer
Ruby on Rails Has Many Through Array Problem
I'm having problems adding to a Has Many Through association using user_ids.
My communication model looks like this:
class communication
has_many :recipients
has_many :users, :through => :recipients
end
In my create action for the communication…
user151419
0
votes
1 answer
Rails: pull value from has_many :through relationship in model
User
has_many :reservations, :dependent => :destroy
has_many :events, :through => :reservations
Reservation
belongs_to :user
belongs_to :event
Event
has_many :reservations, :dependent => :destroy
has_many :attendees, :through =>…

Meltemi
- 37,979
- 50
- 195
- 293
0
votes
1 answer
Updating extra column in a has_many, :through table with Coffeescript
I've got a rather simple setup here: A Doc model, a Publication model, and an Article model.
doc.rb
class Doc < ActiveRecord::Base
attr_accessible :article_ids,:created_at, :updated_at, :title
has_many :publications, dependent: :destroy
…

t56k
- 6,769
- 9
- 52
- 115
0
votes
1 answer
Joining a "has many through" association using ActiveRecord
Working with Exported Data from API
I'm building a leaderboard that displays the Team.name of each team as well as the users who have picked that particular team as their favorites. I'm also populating another attribute Favorite.points; to display…

asing
- 385
- 2
- 7
- 16
0
votes
1 answer
Getting names of all children in has_many, :through
I've got this bit of code which returns an array of IDs like [1, 2, 3]:
<% @articles.each do |a| %>
<%= a.brand_ids %>
<% end %>
Article and Brand have a has_many, :through relationship. How would I return a list of the names of each brand…

t56k
- 6,769
- 9
- 52
- 115
0
votes
1 answer
How to implement has_many :through relationship in rails with this example
i've been searching through similar questions but i still don't get how implement this relationship. I have of course three models :
class Recetum < ActiveRecord::Base
attr_accessible :name, :desc, :duration, :prep, :photo, :topic_id
…

Leandro Temperoni
- 435
- 5
- 13
0
votes
1 answer
Rails has_many through set an attribute on creation
I have setup a has_many through association between two models in Ruby on Rails. The setup is as follows. The models are User and Document, the join model is Ownership. The models are defined like this:
class Ownership < ActiveRecord::Base
…

ctpfaff
- 59
- 1
- 9
0
votes
0 answers
has_many users and events... Rails 3.2
I've looked and looked... it just doesn't make sense to me yet. I don't know when to use has_and_belongs_to_many vs has_many through:
So, calendaring. A user creates an event. Some people that are invited can view the event (through a…

Dudo
- 4,002
- 8
- 32
- 57
0
votes
2 answers
Creating form to update relationship table and model table
I have 3 models:
event
vendor
vendor_relationship
Every event has multiple vendors through that relationship.
Now I want to create a form at /events/1/add_vendors which creates the relationship AND creates the vendor model.
How would I go about…

bjoern
- 1,009
- 3
- 15
- 31
0
votes
1 answer
Rails: Class inheritance and complex polymorphic has_many :through association
The app I'm developing has 3 main models and many single table inheritance models:
Question
User
Professional
Representant
Taxonomy
Category
Topic
Profession
Locality
Region
Country
There are multiple kinds of users (User, Professional < User,…

Jonathan Roy
- 903
- 11
- 20
0
votes
1 answer
Rails 3.2.8 & JQuery Tokeninput: Trying to add new records for has_many through relationship instead of replacing all current records in a form
I have a database of skills that relate to each other as prerequisites to each other. In an index of skills, I'd like to be able to search through other skills and add 1 or more as prerequisites. It's important to note that I ONLY want the user to…

Chris Fritz
- 1,922
- 1
- 19
- 23
0
votes
1 answer
Model association between Company, Employee, and department
I am working in Ruby on Rails 3. And trying to map out three models which mimic the data of a Company its employees and their respective departments.
In arrived at the following solution:
class Company < ActiveRecord::Base
has_many :departments
…
user1929954
0
votes
1 answer
Rails - has_many :through not saving an attribute
Here are my models and associations:
project
class Project < ActiveRecord::Base
...
has_many :projectmemberizations
has_many :users, :through => :projectmemberizations
has_many :project_comments
...
end
project_comment
class…

Trevan Hetzel
- 1,371
- 7
- 21
- 42
0
votes
1 answer
:has_many, :through => association table with multiple attributes updating in form
I am having the hardest time getting this to properly render and update. What is going on, is that I have a many to many association, with the association joining table containing multiple attributes. A case can have many screens, a screen many…

Venice
- 1,858
- 1
- 11
- 10
0
votes
2 answers
incorrect database records created for rails 3 has_many :through association
I have a has_many :through association. Players have many Teams and Teams have many Players. The join model, Affiliation, belongs to Players and Teams, and also has a year attribute to keep track of a player's team affiliation (or employment) from…

glevine
- 697
- 1
- 7
- 19