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

How to make a has_many_through association mandatory for one member?

I have the following models : class City < ActiveRecord::Base has_many :cities_regions_relationships has_many :regions, through: :cities_regions_relationships end class Region < ActiveRecord::Base has_many :cities_regions_relationships …
0
votes
1 answer

Mongoid update_attributes with checkboxes not deleting unchecked values

google was not very friendly about this. I have a Service Model which saves also a relation to a Category Model. class Service include Mongoid::Document has_and_belongs_to_many :categories, inverse_of: :service end class Category include…
Jan
  • 12,992
  • 9
  • 53
  • 89
0
votes
1 answer

has_many :through Survey attributes

I have a Survey which can participated by Participants: Survey has_many: Questions which has_many: Answers A Participant should be able to add his Voting to each of the Answers (values are [-1,0,1] ) One question looks like this: Question 1 -…
Jan
  • 12,992
  • 9
  • 53
  • 89
0
votes
1 answer

Rails habtm with unique values in both join and joined tables

I'm building an app where a user can make a list of places they'd like to get the weather from. So, I have a member model, a place model and a members_places table. Member has_and_belongs_to_many :places, uniq =>…
pedalpete
  • 21,076
  • 45
  • 128
  • 239
0
votes
1 answer

CakePHP searching in multiple HABTM tables

My database: I have companies which HABTM carbrands and HABTM goods My search function: public function search() { $joins = array(); // HABTM if (!empty($this->request->query['Carbrand'])) { $carbrands = array( …
user1327
  • 938
  • 3
  • 10
  • 28
0
votes
1 answer

Cakephp: Many to Many Relationship with checkbox

Currently I have two table Products and Orders joined with HABTM. I would like to add the order by ticking product on the list. Below is the code in OrdersController $products = $this->Order->Product->find('all'); …
Patrick
  • 93
  • 1
  • 2
  • 6
0
votes
0 answers

CakePHP many to many find filtering

I have a many to many relation between products and tags. I need to retrieve products filtered by tags, so I do it this way: $this->Product->recursive = -1; $options['joins'] = array( array('table' => 'products_tags', 'alias' =>…
vonbloom
  • 1
  • 1
0
votes
1 answer

Deleting a HABTM object

I have the following code which gives me an ActionView::Template::Error (undefined methodroster_path' for #<#:0x007fe34005c208>):` While in the background it deletes the association player_roster (Has and belongs to many), but i want to delete it…
Pierre
  • 1,114
  • 2
  • 10
  • 24
0
votes
1 answer

cakePHP: access data in model where are hidden

I have database of library and I would like to display Book detail. Document hasMany Articles and Article hasAndBelongsToMany Authors. In ArticlesController I can see Authors of Articles, but I do not know how to access them in DocumentsController.
Andrew
  • 958
  • 13
  • 25
0
votes
1 answer

Advice on how to define this model/relationship in cakephp

I'm brand new to MVC frameworks and I'm having some issues wrapping my head around how exactly this would be defined in the model. `UserA` purposes `Offer1` `UserB` sees and accepts `Offer1` `Offer` is now complete I originally had the two sets of…
mhopkins321
  • 2,993
  • 15
  • 56
  • 83
0
votes
1 answer

Cakephp HABTM saving -.-

I'm googling high and low on this. I'm not sure where i went wrong cause I don't get any errors. i have 3 tables: MOVIES - id, title, genre, etc GENRES - id, genre GENRES_MOVIES - movie_id, genre_id Movie model: public $hasAndBelongsToMany =…
Marko
  • 1,337
  • 5
  • 18
  • 37
0
votes
1 answer

Multiple nested form in a HABTM relation

I'm fighting with this bug for the past few hours and I can't make sense of it and my researches didn't give an answer. It is a basic HABTM relationship. Inputs HABTM Visualizations, and I have a cross table InputsVisualizations that has some…
0
votes
1 answer

Adding a confirmation to has_and_belongs_to_many

I've got 2 models; Groups and Users. They're related via has_and_belongs_to_many. This works perfectly fine so far; However: I'd like to add a user_confirmed to the story. One user adds another user; Therefore the user isn't confirmed yet. That…
CaptainCarl
  • 3,411
  • 6
  • 38
  • 71
0
votes
2 answers

Rails HABTM relationship not working with polymorphic relationship

I have two models: Student and Project. A student HABTM projects and a Project HABTM students. Here are the two models: class Student < User has_many :relationships, dependent: :destroy has_many :employers, through: :relationships …
0
votes
1 answer

HABTM not working with polymorphic association in rails

I have a polymorphic association: my user model can be of type 'student' or of type 'employer'. I am trying to set up a has_and_belongs_to_many association between the student model and another model called the 'project' model. When I try to…