Questions tagged [has-many-through]

1523 questions
0
votes
2 answers

How to control integrity in Rails has_many :through relationship?

I'm trying to prevent an associated record from being deleted if it has associated records of its own. Rails seems to be subverting the :dependent => :restrict option and executing DELETE SQL anyway. What am I missing? class User <…
Jarrod Carlson
  • 1,967
  • 4
  • 16
  • 20
0
votes
1 answer

How do I associate data with each other using a join table?

I have three models: Lesson, Situation, Fate(join table). In this app, A situation can have many lessons and a lesson can belong to multiple situations. I would essentially like the tables to look like…
Sunwoo Yang
  • 1,213
  • 2
  • 12
  • 22
0
votes
1 answer

How do I setup this complex active record relationship?

I basically want to setup a relationship similar to Netflix's DVD rental model. There are users, and each user has a queue, each queue contains many DVDs and DVDs can have many queues. A queue belongs to a user. I'm not quite sure how to set this…
Matthew Berman
  • 8,481
  • 10
  • 49
  • 98
0
votes
1 answer

Select single row from relation table in Rails

Is there a simpler way of returning the relationship row from a table to access the data stored there? I have two models related using has_many :through and the third model set up as the in-between. My models consist of a User, Recipe, and…
0
votes
2 answers

ruby on rails has_many through relationship

Hi i'm having a little trouble with a has_many through relationship for my app and was hoping to find some help. So i've got Users & Lectures. Lectures are created by one user but then other users can then "join" the Lectures that have been…
0
votes
1 answer

What's the rails way to include a field in a join model when listing an association?

So if I have the following relationship class Item < ActiveRecord::Base has_many :item_user_relationships has_many :users, :through => :item_user_relationships end class User < ActiveRecord::Base has_many :item_user_relationships …
paulnsorensen
  • 448
  • 4
  • 10
0
votes
4 answers

has_many through update issue

Been trying to sort this for over a day now, and I am sure that it is something simple that I am missing. I have a project, which can have one main category and two optional categories. My relevant code for the project model: has_many…
Vikram Goyal
  • 159
  • 1
  • 13
0
votes
1 answer

Difference between memory and database calls

Ok, my main problem on my first project was speed. I don't know which is which, between memory and database calls. I have two questions: How can I differentiate a database call from a memory call (if that's how its called)? I had encountered an…
0
votes
3 answers

Proper Rails Association to use

I am trying to create an association between two tables. A student table and a computer table. A computer can only ever be assigned to one student (at any one time) but a student can be assigned to multiple computers. This is what I currently have…
Dan
  • 2,299
  • 2
  • 20
  • 41
0
votes
2 answers

Setting up has_many through correctly in Rails

Yesterday I asked a question about setting up has_and_belongs_to_many relationships between models in Rails. I eventually got those relationships working, however, I realized that I needed to store additional information in my join table, which…
0
votes
1 answer

has_many through sql

Well my models are User, Exercise and Writing. class User < ActiveRecord::Base has_many :exercises, :through => :writings has_many :writings end class Exercise < ActiveRecord::Base has_many :users, :through => :writings has_many…
0
votes
2 answers

datepicker doesn't save date

I have a join table Writing between tables User and Exercise. My model is class Writing < ActiveRecord::Base belongs_to :user belongs_to :exercise attr_accessible :writing_date, :exercise_id end I followed this Guide for The has_many…
0
votes
1 answer

How to edit has_many through association

I'm struggling with this since a few days now and finally decided to ask even if I feel it should not be that hard to implement. I'm using rails 3.1 and I want to be able to edit in a single form several records of the join table of a has_many…
moncino07
  • 47
  • 1
  • 13
0
votes
1 answer

rails 3.1 complex find_by_sql query on nested has_many through models

My simplified rails app looks like this # chapter.rb has_many :sections has_many :videos, through: :sections # section.rb belongs_to :chapter has_many :videos # video.rb belongs_to :section has_many :votes # vote.rb belongs_to :video What I want…
n_i_c_k
  • 1,504
  • 10
  • 18
0
votes
1 answer

How do I set an attribute on the join model when using accepts_nested_attributes_for?

Is it possible to set an additional attribute on the join model when using accepts_nested_attributes_for? I have User, Account, and Role models. The Account model accepts nested properties for users. This way users can create their account and user…
Mohamad
  • 34,731
  • 32
  • 140
  • 219
1 2 3
99
100