Questions tagged [has-and-belongs-to-many]

A has_many :through association set up a many-to-many connection with another model.

In Ruby on Rails, a has_many :through association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model.

1372 questions
0
votes
1 answer

Rails subset select always returns true

I am trying to search a dataset for a value. If the dataset contains the value, the app does something. If it does not, the app does something else. The data breaks down like this: I have affiliates and users, each with a HABTM relationship to the…
Kevin Whitaker
  • 457
  • 1
  • 6
  • 12
0
votes
0 answers

Rails undefined method future_auctions

I have two models: User and FutureAuction class FutureAuction < ActiveRecord::Base has_and_belongs_to_many :users end class User < ActiveRecord::Base has_and_belongs_to_many :future_auctions devise :database_authenticatable, :registerable, …
0
votes
1 answer

rails has_and_belongs_to_many or manual implementation

I'm designing a ruby on rails app for a pharmacy, and one of the features is that there are stores who have pharmacists who work there. In addition, there are pharmacists, who can work at many stores. This sounds like a job for HABTM, right? …
Eric S.
  • 111
  • 7
0
votes
1 answer

rails formtastic habtm in and out

EDIT: looking for this: http://diminishing.org/extending-formtastic-with-a-sprinkle-of-jquery (If this works I'll answer my own question) I've started to create an in and out type habtm (has many and belongs to many) form through formtastic. …
nictrix
  • 1,483
  • 1
  • 17
  • 34
0
votes
0 answers

HABTM inner join CakePHP 2.0

I have 5 tables: tournaments, rounds, videos, rounds_tournaments, rounds_videos Relations: Tournament hasMany Video Video belongsTo a Tournament Tournament HABTM Round Round HABTM Tournament Video HABTM Round Round HABTM Video What I want to…
Gilko
  • 2,280
  • 8
  • 36
  • 45
0
votes
1 answer

How can I correct a 'SystemStackError (stack level too deep)' on HABTM relationship?

I'm trying to debug/resolve an error I'm getting when trying to add to an association on my report model. I keep getting a SystemStackError (stack level too deep) error that I've read is likely due to an infinite loop call -- but I can't seem to…
0
votes
1 answer

Set id on a csv import for a has_and_belongs_to_many relationship

I have two models in my app: list.rb and contacts.rb, they have a has_and_belongs_to_many relationship. I have the following method in my contacts_controller.rb: def import Contact.import(params[:file]) redirect_to contacts_path, notice:…
Jan
  • 239
  • 1
  • 4
  • 17
0
votes
2 answers

How to count element from belogsToMany relation [Laravel 5]

Here is my relation: public function commentsCount(){ return $this->belongsToMany('App\Comment','project_comment'); } I am trying to get acount of all comments... Here is my query $count = Project::with(['commentsCount' => function($q) { …
Vladimir Djukic
  • 2,042
  • 7
  • 29
  • 60
0
votes
1 answer

Newbie Rails HABTM association not working

I'm new to Rails and trying to create a has_and_belongs_to_many relationship between orders and items. class Order < ActiveRecord::Base has_and_belongs_to_many :items end class Item < ActiveRecord::Base has_and_belongs_to_many…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
0
votes
0 answers

Rails Many to many relationships with connecting or cloning two table with references?

I'm a new with Rails and I'm having trouble with some types of associations that seem a bit more complex than the ones I've been exposed to so far. Zombie_users Body_parts_status Body_parts | id | name | | id |…
0
votes
1 answer

Limiting down the amount of calls to the database during a simple_form with multiple HABTM

I am currently trying to speed up an old (3.2) Rails app and hitting an issue with way too many calls being made to the database during an edit view using simple_form Here is the simplified setup; class Event HABTM Speakers HABTM Sponsors class…
Toby
  • 8,483
  • 13
  • 45
  • 68
0
votes
1 answer

Rails: HABTM Relationship. Retrieve the object that has two references

I have these models class User < ActiveRecord::Base has_and_belongs_to_many :chats end and class Chat < ActiveRecord::Base has_and_belongs_to_many :users end Which is a many_to_many relationship and what I want is to recover the only…
0
votes
1 answer

Rails: UI to add children from large record set to parent model in HABTM relationship

Given the parent / child HABTM relationship: class List < ActiveRecord::Base has_and_belongs_to_many :items end class Item < ActiveRecord::Base has_and_belongs_to_many :lists end I need to set up a UI to add Items (children) to a List (parent)…
0
votes
0 answers

ActiveAdmin saves has_and_belongs_to_many fields chosen but doesnt take effect

I have written the necessary code including the join table to create the many to many relationship between category and products and it works from testing in the rails console. When I chose more than one category field it saves them and stays there…
0
votes
2 answers

HABTM association between models named with underscore

I have got the following problem: My Rails app has many models, but I have a problem with the association between two of them: class RedArticle < ActiveRecord::Base has_and_belongs_to_many :red_sections end class RedSection < ActiveRecord::Base …