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

has_and_belongs_to_many with possible through solution

i have been banging my head against the wall for the past few hours with this problem, i can't seem to figure out myself. Okay i have two models that look like this class Book < ActiveRecord::Base has_and_belongs_to_many :categories end class…
user2945241
  • 360
  • 5
  • 19
0
votes
2 answers

Input HABTM details after adding a user

I have a CakePHP-based application in development which acts as a user management tool in a Moodle-powered university and connects to Moodle's database. Therefore the models we will have are: Users, Groups (Used as academic years, such as 2nd of Law…
fernandopcg
  • 514
  • 6
  • 20
0
votes
1 answer

CakePHP HABTM relations listing

I'm have quite a problem while trying to make a list (for the admin section) of HABTM relations. Here's the deal: permissions: id, name; users: id, username; permissions_users: permission_id, user_id Permission HasAndBelongsToMany User I want to…
pawelmysior
  • 3,190
  • 3
  • 28
  • 37
0
votes
2 answers

rails HABTM joins and inconveniences

I have a working HABTM association between the models Posts and Users... the posts_users table is as advertised and both have the necessary has_and_belongs_to_many in their model.rb And if I use User.find(1).posts it will find all the posts with the…
holden
  • 13,471
  • 22
  • 98
  • 160
0
votes
0 answers

Cakephp Pagination is not working with HABTM

So I have 2 Models Performer Model: class Performer extends AppModel { public $actsAs = array('Containable'); var $name = 'Performer'; var $hasAndBelongsToMany = array('Genre'); } Genre Model: class Genre extends AppModel { var…
Nick
  • 59
  • 2
  • 9
0
votes
1 answer

Searching CakePHP HABTM relationship for results where 'all' terms match, not 'any'

In CakePHP 2.4, I'm trying to generate conditions for a search query that searches for data that has been tagged across a HABTM relationship. My problem is twofold: I can't get my query to return only data tagged with ALL of my search terms, and I…
caitlin
  • 2,769
  • 4
  • 29
  • 65
0
votes
1 answer

Create join model record with accepts_nested_attributes_for

I have following models class User < ActiveRecord::Base has_many :project_users, dependent: :destroy has_many :projects, through: :project_users end class ProjectUser < ActiveRecord::Base belongs_to :user belongs_to :project has_many…
0
votes
2 answers

How to find data using HABTM through

I have User HABTM through Solicitation that is SocilitationUser model. When I do debug($this->User->find('all')); i get this array array( (int) 0 => array( 'User' => array( 'password' => '*****', 'id' => '1', 'username'…
Igor Martins
  • 2,015
  • 7
  • 36
  • 57
0
votes
1 answer

CakePHP and HABTM Tag Filtering

I am wrestling around a bit with CakePHP HABTM relationships, and I've gotten stuck trying to do a seemingly simple task. I have many Camps and many NewsItems. Each NewsItem could be relevant to any of the camps, so when a user creates a NewsItem,…
just_wes
  • 1,288
  • 14
  • 25
0
votes
1 answer

Display Image next to HABTM checkboxes

Cane Somebody give me an ideas on this Please! I Generate multiple checkboxes from a table that is related with another table with HABTM relationship association. I would like to generate multiple checkboxes with an image along with the text in the…
erlandmuchasaj
  • 232
  • 4
  • 16
0
votes
2 answers

CakePHP - HABTM - adding multiple tags to multiple points

I am trying to 'tag' multiple 'points' with multiple tags. I'm tagging my single points successfully. Unfortunately, when i try and use a tag, such as 'test2' on another point as a tag it is either giving me a duplicate entry error if i have my…
zmonteca
  • 2,304
  • 1
  • 26
  • 26
0
votes
1 answer

Rails HABTM association with renamed classes

I'm creating a simple game site where users can create games and invite other users to join their games. A User can be both an owner of a Game and a player within that Game (the owner must also be a player) through the :game_players join table. I…
kid_drew
  • 3,857
  • 6
  • 28
  • 38
0
votes
1 answer

Complex forms - Managing multiple models in a single form - (3rd degree madness)

I have isolated the problem in the second block of code below (if you don't want all the details): I can create new users from the account model. I can't assign those users roles from the accounts model. I am using fields_for, this method does not…
JZ.
  • 21,147
  • 32
  • 115
  • 192
0
votes
1 answer

Rails: change database model on production enviroment

i need to convert some data, but not sure how to do it. I have a professional model, which had an foreign key. We decided that wasn't enough and changed the "has many" to a HABTM model, but now in the production environment, i need to convert the…
Techmago
  • 380
  • 4
  • 18
0
votes
0 answers

Deleting Associated table Data from HABTM relation in Cakephp

My relationship is like PostTag When I add a new post and corresponding tags it is saving in posts table and tags table and save the ids of both in posts_tags table. Everything is working fine with cakephp HABTM, but now I want…
SibinF
  • 385
  • 1
  • 7
  • 25