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

Rails: How can I implement this relationship between these models? habtm? habtm through? Polymorphic?

I am storing my files on Amazon s3. Each file has many "consumers" and these consumers can be of any type(users, external apps, business_listings, etc). This calls for a many to many relationship. However, I also want to store certain attributes…
0
votes
1 answer

CakePHP - How to get posts of people the user is following in Twitter Clone?

I am trying to build a Twitter Clone with CakePHP. I have a HABTM relationship set up between my models (I'm not a 100% sure if I did this correctly or not). I have 3 tables in my database: users (id, username, password) tweets (id, tweet_msg,…
user1302430
  • 342
  • 3
  • 6
  • 14
0
votes
3 answers

Rails/AR find where habtm does not include

I have a Rails app with Users, and each user HABTM Roles. I want to select Users without a specific role. I have searchlogic at my disposal, and I'm lost. I've tried using a combination of conditions and joins and includes and what not, but I can't…
Daniel Huckstep
  • 5,368
  • 10
  • 40
  • 56
0
votes
1 answer

Is it possible to insert all related records in a HABTM at once with saveAll in Cakephp?

I have two models: Action HABTM Image I don't have a form 'cause I'm generating the Post data with code outside of cakephp. In the Post I'm sending this data to the ActionController to be saved: data[Action][id] =…
eleonzx
  • 677
  • 10
  • 16
0
votes
5 answers

How do I join two tables in a third n..n (hasAndBelongsToMany) relationship in CakePHP?

I have a n...n structure for two tables, makes and models. So far no problem. In a third table (products) like: id make_id model_id ... My problem is creating a view for products of one specifi make inside my ProductsController containing just…
Fernando Barrocal
  • 12,584
  • 9
  • 44
  • 51
0
votes
1 answer

Saving and reading three models in Cakephp

I was working around join three models. I have Hospital, Doctor and Specialty. A Hospital hasAndBelongsToMany Doctor and a Doctor hasAndBelongsToMany Specialty. So 1 doctor could work in 1 Hospital with 1 specialty, but the same doctor could work in…
0
votes
1 answer

CakePHP 2.0: Using paginate with hasMany and HABTM

I have the following relationship: Post hasMany Comment Post belongsTo Category Post HABTM Tag I want to use the paginate method with those properties: public $paginate = array( 'published', 'limit' => 3, 'fields' => array( …
grssnbchr
  • 2,877
  • 7
  • 37
  • 71
0
votes
2 answers

post habtm postlover : how to order posts by number of postlovers?

please help me, i'm really struggling with this... Authors can write post, and authors can love other authors' posts... So posts belong to author (when authors write them), but posts habtm authors (when authors love them). For example i'd like to…
checcco
  • 35
  • 4
0
votes
1 answer

Best way to bypass cakePHP's HABTM auto-magic?

My question is in relation this this answer. https://stackoverflow.com/a/8773953/1297775 I have read at many places, what @deceze put as: "To be quite honest, for any halfway complex application, relying on Cake's automagic handling of HABTM…
Gurpreet Singh
  • 153
  • 1
  • 3
  • 14
0
votes
1 answer

In a single form, linking two instances of two models with habtm

I am using Rails 3. I have a Product model and a Group model (a group has_many users, through membership). I would like to build the new.html.erb form for the product model, and at the end of the form, I would like the user to be able to choose…
citraL
  • 1,146
  • 1
  • 10
  • 25
0
votes
1 answer

ruby on rails fill association table

I have a table of recipes, a table of ingredients and an association table (a recipe "has and belong to many" ingredient and an ingredient "has and belongs to many" recipe). I do not have a controller or a model for the association table. I want to…
user429400
  • 3,145
  • 12
  • 49
  • 68
0
votes
1 answer

Ruby on Rails - HABTM - Inserting data into 2 models in one controller

I'm a beginner in RoR and am having issues on working with some of my models. Basically I have a habtm relation between a product-ticket-reservation. A product habtm reservations through tickets and vice-versa. I also have a Supplier, which has_many…
Silver
  • 693
  • 1
  • 10
  • 27
0
votes
1 answer

CakePHP & MVC – Potentially superfluous SQL queries when looking up 'names' associated with ids

I've probably murdered the whole concept of MVC somewhere along the line, but my current situation is thus: I have participants in events and a HABTM relationship between them (with an associated field money_raised). I have a controller that…
rbobbington
  • 123
  • 6
0
votes
1 answer

CakePHP HABTM – List all related items

I'm very new to CakePHP (and only slightly less new to MVC concepts) and am trying to build a system with a HABTM relationship between events and participants. I'd like the index page to display a list of events in a table, with one cell of each row…
rbobbington
  • 123
  • 6
0
votes
1 answer

Error in Assigning an attribute to a resource in rails

I am trying to allow a current user to invite another user and have that new invitee be assigned to a listing, but am getting an error when the invited user goes to sign up. There are two models, User and Listing, that are related with a…
John
  • 13,125
  • 14
  • 52
  • 73