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

Can I have an automatically generated HABTM table in CakePHP?

Here's my situation...I am making a website of games. Each games has many modes, and each game also has many puzzles. For example, if the game is a word search game, a puzzle will be a unique grid of letters, and a mode will be how the game is…
Nick Manning
  • 2,828
  • 1
  • 29
  • 50
0
votes
1 answer

Error "Missing Database Table" when using HABTM

I have a problem with HABTM in Cakephp. There is two models: User (musicians) and Genre. And there is three tables: users, genres, genres_users (id (primary), genre_id, user_id). Wrote in User:
biosvs
  • 11
  • 3
0
votes
1 answer

Checkboxes selected on edit - HABTM models

I have 2 models: Attorney and Powers. Where: Attorney HABTM Powers When I add a new Attorney, I select many checkboxes that correspond to the Powers. My question is: When I edit an Attorney, how do make the checkboxes appear selected? Sorry my bad…
Igor Martins
  • 2,015
  • 7
  • 36
  • 57
0
votes
4 answers

Deleting a record in a has_and_belongs_to_many table - Rails

I've been looking, and can't find a good answer for how to delete records in a HABTM table. I assume a lot of people have this same requirement. Simply, I have Students, Classes, and Classes_Students I want a student to be able to drop a class, or…
Arel
  • 3,888
  • 6
  • 37
  • 91
0
votes
1 answer

Ransack's collection_select and HABTM return undefined method

I've been looking over my code over and over again and I can't see my problem. I have two Models Person and Credential. They have a HABTM relationship. Person class Person < ActiveRecord::Base attr_accessible :credential_ids …
Mundo Calderon
  • 183
  • 2
  • 10
0
votes
1 answer

HABTM Search by multiple associated records

Following issue: I have the ID of a Product and two IDS for Option Values. I want to look up the Variant that matches the Product ID and the two Option Value IDs. So for an Example: I have a Product called "Tshirt" and the one I want, is Blue and…
Martin Lang
  • 831
  • 11
  • 20
0
votes
1 answer

CakePhp 2.x HABTM SaveAll

I'm trying for 3 days to make it work, already apply all i have seen on stack/forums/google. A subscribers habtm subrcriberlist and a subscriberslist can belongs to many subscribers. /* Subscriber model*/ public $hasAndBelongsToMany = array( …
Flo
  • 1
0
votes
1 answer

HABTM or HM/HMT Self-Join in Rails

I have a Users model and want users to be able to Subscribe to another User to get notifications when they post things. This is sort of a has_many self join and a many_to_many self join. I need to be able to type @user.subscribers and…
dewyze
  • 979
  • 1
  • 7
  • 21
0
votes
1 answer

Retrieving data through two model relationships

I'm trying to retrieve some data through two model relationships with CakePHP. The models and their associations are as follows: User hasOne Profile HABTM Skill I would like the user's skills to be returned when I do a find() operation on the User…
James Dawson
  • 5,309
  • 20
  • 72
  • 126
0
votes
1 answer

MySQL: Join HABTM tables and then update a column with a count of the results

What I want to do must be broadly applicable, but it's hard to describe, so I'll give a dummy version of my circumstances (pretend posts are sometimes co-authored): Table A: Users id | name |...demographics....| post_count |…
Jonline
  • 1,677
  • 2
  • 22
  • 53
0
votes
1 answer

HABTM-Relation : Create a relation for all other records

If i want to add a record to TABLE A, is there an efficient way to add a record in the JOIN TABLE for many (or all) records in TABLE B? I try to build a simple task management (in CakePHP). An user adds a task and there will be added a connection…
Benedikt
  • 954
  • 3
  • 14
  • 25
0
votes
1 answer

CakePHP 2.0 twitter-like follow button

I can't help myself and it's currently annoying, and yes, I used google a lot. What I need: A twitterlike follow button with the action to follow user. What I already did: Database users table: id, username, password, ... users_users table: id,…
0
votes
1 answer

Having a hard time with has_and_belongs_to_many associations. Not sure how to add objects to a specified instance of its "belongs_to" table

I'm building an app where a User can create a Group and then invite other Users to join his group. A User can join many Groups and a Group will include many Users. I'm confused as to how I can add a specified user to a specified group. For example I…
0
votes
1 answer

HATBM, how to write into lookup table and only into one of the associated tables, not in both?

The question is: given two models A and B being in HABTM association, when I create new instance of A, how to instruct Rails not to write to A, B and A_B, but just to A and A_B? So, more precisely: I have two associated models: Balloon and…
Andrew
  • 2,148
  • 5
  • 23
  • 34
0
votes
1 answer

How to select the values dynamically from select box based on the previous select box?

I am sorry if i cannot make you understand. I have two tables where the first table contains categories and the next one contains sub-categories and i have another table item where i have has_and_belongs_to_many relation with sub-category table.…
logesh
  • 2,572
  • 4
  • 33
  • 60