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
0 answers

Adding hasMany relation to HABTM join table

I'm stuck with something that is killing me! So, I have Order HABTM Product (with a products_order join table) The join table looks like id | product_id | order_id | quantity | price At the moment, when I'm making a find call I have the following…
azerto00
  • 1,001
  • 6
  • 18
0
votes
1 answer

CakePHP HABTM relationship

I have several tables: ingredients, customers, recipes, menus and restaurants. The conditions are: ingredients HABTM customers, recipes HABTM ingredients, menus hasmany recipes and restaurants hasmany menus. However, when I try to cake bake all…
Kelvin
  • 873
  • 2
  • 9
  • 20
0
votes
1 answer

CakePHP SET library and HABTM extract

I need your help because I can't extract results as I want from my query result without doing a foreach loop. My query returns an array like this one : array( (int) 0 => array( 'Event' => array( 'id' => '1', 'title' => 'Event…
0
votes
1 answer

HABTM Manual Assocation

I'm still a big noob to rails so I hope someone can help! I have two models, Companies and Contacts with a HABTM between them. Both have controllers in place for CRUD. What I would like to be able to do, for example, is on the Company view page,…
0
votes
0 answers

Rails: STI with roles and HABTM

In the app I am working with here are the User models... class User < ActiveRecord::Base has_and_belongs_to_many :roles end class Athlete < User end class HighSchoolCoach < User end A user can have a role of SchoolAdmin which grants them…
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189
0
votes
1 answer

Edit of self referencing HABTM in cakephp works, sometimes

I'm using a self referencing HABTM model with Participants. You sign up for an event and when you log in to your reservation/profile you see a list of other participants and you can choose to add yourself and others into various groups; share hotel…
user230797
0
votes
2 answers

Two Linked Models + User Model?

I am trying to create the following basic structure with RoR. The key is that all Users also be linked to a School and a Major. Users will write articles based on their School and Major. The linking is not exclusive: many users can be in one of many…
0
votes
1 answer

Cant get the view to save an assotiation data

what i need to made to make the create action works? i hava a table with a has_and_belongs_to_many association. The "new" page works fine, but when i select itens and try to save it raises an error: Can't mass-assign protected attributes: book_id I…
Techmago
  • 380
  • 4
  • 18
0
votes
1 answer

Rails HABTM quantity

I'm developing a order system. Models: Orders Products OrderProducts Every product have their own quantity field that tells the user how many there are. I want to be able to order more than one of the same product and mutiple products. ie.…
Philip
  • 6,827
  • 13
  • 75
  • 104
0
votes
1 answer

rails 3 has_and_belongs_to_many doesn't assign record

I have two models User and Conf. They have has_and_belongs_to_many relationship. When I try to create a new conf, app is recording it to confs table but not confs_users table. So doesn't assign new record to users. conf.rb class Conf <…
0
votes
1 answer

rails 3 has_and_belongs_to_many NoMethodError undefined method `each' for nil:NilClass

I have two models User and Conf. They have has_and_belongs_to_many relationship. When creating a new conf object, I want to assign it to multiple existing users but I got this error: NoMethodError in Confs#create undefined method `each' for…
kalahari
  • 895
  • 5
  • 15
  • 34
0
votes
2 answers

How to delete record from only associated table with has_and_belongs_to_many relation ship

I have two model hotel and theme and both has has_and_belongs_to_many relationship and third table name is hotels_themes, So I want to delete record only from third tables hotels_themes. hotels_themes; +----------+----------+ | hotel_id | theme_id…
0
votes
2 answers

using scopes with parameters and has_and_belongs_to_many associations with ActiveRecord (Ruby)

In my Sinatra app my model defines a HABTM relationship between Users and Notifications. I am trying to define a couple of scopes, one for all Notifications associated with no Users called unread and one that returns all Notifications that are…
0
votes
1 answer

How to add additional attributes to the join table in HABTM and fetch that when getting association values?

I have two models User and Category. Consider the following code class User < ActiveRecord::Base has_and_belongs_to_many :categories accepts_nested_attributes_for :categories, :allow_destroy => true alias_method :categories=,…
0
votes
1 answer

Cakephp HABTM association save not working

view.ctp Session->check('Auth.User.id')) { $userid = $this->Session->read('Auth.User.id'); } ?>

CMS scripting
  • 669
  • 1
  • 7
  • 13