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

CakePHP - How to get a threaded find on a habtm model?

Lets say I have the following tables: categories, posts and categories_posts. Category acts as a Tree. There is a habtm between Category and Post. What I want to do from the Posts Controller is find a specific Post and list the Categories it belongs…
ryan
  • 33
  • 1
  • 7
0
votes
1 answer

Cake HABTM not deleting rows in join table correctly

This has been causing me considerable grief for a couple of days now, so I turn to the community for help. Assume two tables - Album HABTM Customer The join table is customer_albums PK(album_id, customer_id) I have two controller functions: public…
Mark
  • 436
  • 4
  • 18
0
votes
1 answer

CakePHP: complicated join model

following scenario: Recipe hasMany RecipeItem RecipeItem belongsTo Recipe, Ingredient (Ingredient could be associated with hasMany RecipeItem, but I don't need that relation.) so basically, a one sided HABTM without the join table, because my…
Eike Cochu
  • 3,249
  • 7
  • 34
  • 57
0
votes
2 answers

Table relationship - multiple HABTM or multiple hasMany

I have a table files and it belongs to one either post, article, notion or paragrah. Maybe in the future, there will be more. What relationship do you suggest to use? Multiple HABTM tables, or multiple columns (post_id, aticle_id,...)? Or maybe two…
0
votes
1 answer

Two rails models both with a habtm relationship to a third model

I have a question about has and belongs to many when it applies to multiple models. I've seen a couple other similar questions about habtm with multiple models but none quite like this (they usually apply to two models, not three). Suppose I have…
hershey
  • 465
  • 1
  • 8
  • 19
0
votes
1 answer

How to create a rating system for has_many - has_and_belongs_to_many relation in Rails

I have an app where: User has_many Openings Opening belongs to User & has_and_belongs_to_many Categories Category has_and_belongs_to_many Openings I'm trying to create a rating system where the user rates each opening per category, and am struggling…
0
votes
2 answers

Rails habtm nested select doesn't has right selected value on edit

I have the following models in my RoR project: scope and project_scopes. Project has_many :scopes, through: :project_scopes. Also project accepts_nested_attributes_for :project_scopes. I add scopes to projects by several…
0
votes
1 answer

Ruby on Rails - Devise Confirmable

Im a RoR rookie and am using rails 3.2.3. I've been using devise and so far it has been great, however, I've run into a problem. I have a User table with devise and a HABTM association with a Role table. I have the join table created and everything…
0
votes
1 answer

Search Through HABTM Checkbox/List

I have this contact form which also relates to a few other tables with a HABTM relationship. They are displayed in the form either as a list or as checkboxes. What I want is to be able to search through them while still in the form to select those…
jase89
  • 75
  • 2
  • 7
0
votes
1 answer

Cakephp HABTM removing extra fields

I have models named Place and Category which are connected using an HABTM relationship. Now when i read specific fields from Place, i get additional fields in the result like this. array( 'Place' => array( 'id' => '8' ), 'Category' => array( …
dinkan
  • 83
  • 4
  • 13
0
votes
2 answers

Deleting Data for HABTM in cakephp

i am a new beginner in cakephp. I am trying to do a deletion based on HABTM relationship, but failed. Please help me. I have three tables: products, users and users_products table. one product can have many users and one user will have many…
onegun
  • 803
  • 1
  • 10
  • 27
0
votes
2 answers

CakePHP HABTM question

Might be a newbie question as I'm trying to see what all these "PHP frameworks" are at my free time. For starters I want to add multiple tags to multiple photos. I have a tags model and mot model (the photos). Snip of mot model: var…
jpou
  • 1,935
  • 2
  • 21
  • 30
0
votes
1 answer

belongs_to won't associate records even with the correct Id stored

When a User is created a Team is created and the User is set as the owner of that team and also set as a member of that team. A User can be a member of many Teams and Teams can have many members. Each User can own only one team and a Team can have…
0
votes
1 answer

Rails HABTM association

I have self reference habtm assotiation. class Label < AR::B has_and_belongs_to_many :a_label, :class_name => "Label", :join_table => "a_labels", :foreign_key => "label_id", :association_foreign_key =>…
0
votes
1 answer

How to access data out of a join table in Rails 3

I have a has_and_belongs_to_many association between a user and a task. I wanted a user to join a task and created an action in the user controller as follows: def joinTask @user = current_user @task = Task.find(params[:id]) …
cruxi
  • 819
  • 12
  • 28