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 HABTM relationship issue

I'm trying to create a social networking type of website where a user can send/receive a friend request. In our current system when a user sends a request half the required information is stored in the database then when a user accepts the rest of…
user1402677
  • 269
  • 2
  • 12
0
votes
1 answer

Ruby on Rails - HABTM assign after create

I'm using rails 3.2.3 and am having trouble assigning a value in my HABTM relation. Basically I have got 2 models, Product and User. When I create a new Product, I want to insert in the Products_Users middle table the inserted values. It has to be a…
Silver
  • 693
  • 1
  • 10
  • 27
0
votes
1 answer

verifications when inserting content into HABTM tables

I have set up my first HABTM tables (hosts and owners) with a join table (hosts_owners). My tests seem to be working fine and similarly so do the web pages. So, my next question is how to insert new data and their respective relationships (ie.,…
moosya
  • 1
0
votes
1 answer

cakephp form habtm jQuery autocomplete and add multiple

Calling all cakephp gurus. Here is a tough one. I have a form that has a habtm relationship. Instead of adding hundreds of checkboxes in a form to select a customer or two an auto complete search on a habtm with a drop down of nearest to names with…
0
votes
1 answer

How do I split my HABTM tags?

I want to take a field in the add form of the Post, explode it at the spaces, and save each word as a Tag, which HasAndBelongsToMany Post. So, for each unrecognized tag, it will create a new one, but if the Tag already exists, it will only create a…
tyjkenn
  • 709
  • 10
  • 25
0
votes
1 answer

cakephp HABTM association saveAll?

I have two tables and a join table. I tried using the $hasAndBelongsToMany but it didnt work, so instead i create a model for the join table and used. User hasMany Membership Membership belongsTo User, Club Club hasMany Membership. I have a form…
madphp
  • 1,716
  • 5
  • 31
  • 72
0
votes
1 answer

Ruby on Rails - HABTM NoMethodError

Im using rails 3.2.3 and am having issues with HABTM relationships. Basically, I have a User model, with has a HABTM with a Role model. Everything works fine, however, I now want to add another HABTM relation between the User model and the Hotel…
Silver
  • 693
  • 1
  • 10
  • 27
0
votes
1 answer

CakePHP saving data in HABTM fields

I am using these three relations User, Movie and UsersWatchlist.. Where users_watchlists contains movie_id and user_id as attributes.. I have this structure array( 'User' => array( 'id' => '3' ), 'UsersWatchlist' => array( 'UsersWatchlist'…
user1275378
0
votes
1 answer

Ruby on Rails - Devise and Active Admin single model HABTM

Im using rails 3.2 and am having trouble using pre-created devise alongside active admin using a single model and an HABTM relation to a Role model. I've followed this tutorial…
0
votes
3 answers

ruby on rails - after establishing many to many connection - how do I display data

I have established many to many relation with the help of this site. I have added has_and_belongs_to_many in the model Now I want to display data from that object on the screen I assume I should do it in the html.erb lets say that I want it on the…
Bick
  • 17,833
  • 52
  • 146
  • 251
0
votes
1 answer

CakePHP 2.1 hasAndBleongsToMany or hasMany through?

I'm new to the hasAndBelongsToMany relationships in CakePHP. I'm trying to figure out the best way to implement the following scenario. Do I use hasAndBelongsToMany or hasMany through? In my application I am creating Repair Orders. The Repair…
Stewie
  • 117
  • 1
  • 1
  • 9
0
votes
1 answer

HABTM relationships in ExpressionEngine

Is ExpressionEngine capable of handling HABTM (has and belongs to many) relationships, even if it's with a plugin? Basically, I have two channels: recipes and ingredients. A user needs to be able to create a recipe by assigning entries from my…
Martin Bean
  • 38,379
  • 25
  • 128
  • 201
0
votes
4 answers

Sorting habtm data in rails

I have the following database: class User < ActiveRecord::Base has_and_belongs_to_many :apps class App < ActiveRecord::Base has_and_belongs_to_many :users In the view for a User (users/show.html.haml) I want to list all the Apps sorted by the…
James Brooks
  • 4,135
  • 4
  • 26
  • 25
0
votes
2 answers

collection.exists? lies to me

In my ruby model I have a has_and_belongs_to_many relation with a model "search": has_and_belongs_to_many :searches I want to add a new search object only if it does not already exists, so I wrote: def append_unless_already_there search unless…
Jos
  • 1,015
  • 2
  • 13
  • 25
-1
votes
2 answers

How to deal with 2 different type of associations with same table in rails?

I am creating my first rails application and stuck at this point for a long time. So I have two models in my project. Users (created through devise gem) Projects There are two associations of these two models with each other. As each project can…