Questions tagged [has-many-through]

1523 questions
0
votes
1 answer

Rails helper for a nested member of a has_many through is routing incorrectly

I have a has_many :through relationship where feed has_many lists. Routes resources :feeds do member do resources :feed_lists end end Route I'm trying to hit: feed_list DELETE /feeds/:id/feed_lists/:id(.:format) …
cbron
  • 4,036
  • 3
  • 33
  • 40
0
votes
2 answers

how to access data with has_many :through relation

Hi I have three models: company, plan and subscription with following association class Company < ActiveRecord::Base has_one :plan, :through => :subscriptions has_many :subscriptions end class Subscription <…
Ravindra
  • 1,039
  • 2
  • 12
  • 26
0
votes
2 answers

when use has_many :through in rails, can a query yield fields from all three tables?

In my app, the main objects are Accounts and Phones, with a typical has_many :through Contacts, eg: Account: has_many :contacts has_many :phones, :though => contacts Phone: has_many :contacts has_many :accounts, :though =>…
jpw
  • 18,697
  • 25
  • 111
  • 187
0
votes
1 answer

Has many through with different foreign key

I have the following :has_many :through relation. Associations class Profile < ActiveRecord::Base has_many :teams has_many :projects, :class_name => "Project", :through => :teams has_many :leads, :class_name => "Projects" class Project <…
travis
  • 8,055
  • 1
  • 17
  • 19
0
votes
1 answer

displaying join table information with a solr result in the view

I have a collection of Fabrics each Fabric has many colours. My DB association Fabric has_many Colours through Fabric_colours I am using solr to index my Fabrics, so structuring complex SQL queries is not possible. The join model Fabric_colours,…
RMcNairn
  • 491
  • 1
  • 5
  • 20
0
votes
1 answer

Form to create entries in many-to-many relationship with nested models

My application consists of these five models: A supermarket can have different categories of products and the products in these categories can be produced by several brands. Now I want to have one (or two) Selection-field(s) in my supermarket-form…
0
votes
1 answer

Deleting record via has_many :through

My model schema: User has_many :activities has_many :companies through: :activities Company has_many :activities has_many :users, through: :activities Activity belongs_to :user belongs_to :company Problem when I try to run…
Zeck
  • 6,433
  • 21
  • 71
  • 111
0
votes
1 answer

add record via has_many with default scope

Records are added with default scope, but not with required. class PostsTag # published is false by default end class Post has_many :posts_tags {published: true, private: false}.each do |key, val| has_many "#{key}_tags", …
gayavat
  • 18,910
  • 11
  • 45
  • 55
0
votes
1 answer

Ruby on Rails Form for has_many relationship

I have Users who need to answer some questions upon registering. Users has_many Questions through an Answers join table. I am just trying figure out how to create the form on the Users#new action. I am using simple_form. Here is my DB…
0
votes
1 answer

Polymorphic or has_many :through for recording cash flow

So far I've spent a day trying to model the following, which I believe should be simple, I've looked at it too much, and there is probably an obvious solution staring at me.. Objective: Users book clients onto events which can be chargeable, users…
0
votes
0 answers

How to properly perform a new action in rails 3 with has_many through?

OK Updating this question heavily based on progress made, also simplifying this by eliminating some info not pertinent to the problem. I've been reviewing a lot of posts and railscasts about has_many :through but am still having an issue with a…
Dave Collins
  • 1,077
  • 1
  • 15
  • 23
0
votes
1 answer

ActiveRecord associations, has_many_through

I've been trying to wrap my head around these associations and I've run into a bit of a snag. The app I'm working on has 2 models at the moment: Ingredient, and Recipe. The logic behind each is as follows: The Ingredient model contains info on food…
0
votes
1 answer

Updating models in has_many :through association

I have two models, Designer and Influence. They have a "has_many" relationship to eachother :through a join model called Relation. I want to use a single form to create/update the designer model with information from the influence model. Is it…
umezo
  • 1,519
  • 1
  • 19
  • 33
0
votes
2 answers

Saving has_many, :through associations when there are extra attributes in the join table

This question seems to have been asked many times before, but I didn't see it satisfactorily answered anywhere. I have three tables/models: skill ---------------------------------- id label user ---------------------------------- id username (many…
Jason Swett
  • 43,526
  • 67
  • 220
  • 351
0
votes
1 answer

has_many :through method on an inherited class

BACKGROUND: I have a simple has_many :through setup linking Communities and Posts - which allows me to call @community.posts or @post.communities. I also have an Events model, which inherits from Posts OBJECTIVE: I'm wondering if there is a Rails…