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 association and undefined method

I am using devise for authentication in my rails app and was using the 'current_user' method in one of my controllers. Since then, I have set up a 'has_and_belongs_to_many' association between my User and Activity tables as shown below. My issue is…
0
votes
2 answers

Cakephp HABTM deletes always the records which contains a already used id

I try to add a Tag system to my Website. Users can create Tickets and add Tags to them. To do this I have a HABTM relation between the Models Ticket and Tag. My problem is now: When I save a new relation I can have multiple Times the same Ticket id…
Coltaine
  • 1
  • 1
0
votes
0 answers

Delete a record in a Join Table of a HABTM Relationship

The relationship looks like this: Podcasts <-HABTM-> Users How do I delete the association between them (Inserting works fine)? I searched many threads but I couldn't find a working answer for me. This is what I already…
dh762
  • 2,259
  • 4
  • 25
  • 44
0
votes
1 answer

Cant' get all User Data from HABTM in cakephp

I've spent three days working this issue but has come to a dead end and can't proceed. I know how to get the needed data using non cakephp methods, but I prefer to use cakephp's model relation. MY MODELS class User extends AppModel { var $hasOne…
Nick
  • 59
  • 2
  • 9
0
votes
1 answer

Getting data in a HABTM relationship, formatting and sending with Cake's mail-component

Maybe it is a simple question, but I don't know how to approach it. I have a HABTM-relationship between Podcasts and Users and its basic baked application in CakePHP 2.3.6. A User can "subscribe" to podcasts. I'd like to get all podcasts of the…
dh762
  • 2,259
  • 4
  • 25
  • 44
0
votes
1 answer

Authentication with email not username

I followed the basic Authentication tutorial of CakePHP. If I add a user, I can't login with him. The views with the inputs should be alright. Background: Users HASANDBELONGSTOMANY Podcasts with a join table. Controller/Userscontroller.php public…
dh762
  • 2,259
  • 4
  • 25
  • 44
0
votes
0 answers

Baking a HABTM-association

I'm getting the following error and can't see why. I can see that the PodcastsUser is not a table... I baked the whole application with the DB below – Im getting the error just when accessing/Podcasts/view/*Nr*, index etc is fine. THANK YOU! Error:…
dh762
  • 2,259
  • 4
  • 25
  • 44
0
votes
1 answer

How to populate join table for a HABTM relationship Rails 3, postgresql

So after searching long and hard for information that can help us, we've found it difficult to find an answer we can work with. Our problem is that we have two tables joined through a HABTM relationship called Schools and Organizations. A school is…
0
votes
0 answers

Are there any complications to using has_many in relationship with a has_and_belongs_to_many?

So imagine a situation where you have many meals. You can then categorize these meals as you see fit. So the two objects would be class Category < ActiveRecord::Base attr_accessible :name has_many :meal end class Meal < ActiveRecord::Base …
justindao
  • 2,273
  • 4
  • 18
  • 34
0
votes
1 answer

has and belongs to many through

I have a complex relationship that I am having a hard time representing in the views. I need some help figuring out the best way to set up relationships and that will probably solve most of my problem. I've got a diagram here: Diagram Basically I am…
Sean
  • 1,078
  • 14
  • 25
0
votes
1 answer

HABTM: create and link to existing data

UPDATE: I am so sorry. Many hours of trying to fix this problem got my brain off. Of course 'HABTM Checkboxes' railscast was the right answer to this post. As Dany said. Thank you. I'm going into Ruby and Rails and got a problem I can't fix. I have…
blackst0ne
  • 681
  • 6
  • 22
0
votes
2 answers

How to get a subset of has_and_belongs_to_many relationship

In my Rails 3.2 app I have a has_and_belongs_to_many :notes association on Profile. Note has a type on it - "urgent" or "standard". (Note has_and_belongs_to_many :profiles.) I'd like to be able to do something like profile.urgent_notes without…
tvalent2
  • 4,959
  • 10
  • 45
  • 87
0
votes
1 answer

has_and_belongs_to_many works in form but not show

My has_and_belongs_to_many doesnt work in my show view, In the form i am able to select multiple options but they wont display in the show.html.erb My Section Controller class Section < ActiveRecord::Base attr_accessible :about,…
PMP
  • 231
  • 6
  • 25
0
votes
0 answers

rails many to many relationship from the beginning (all model creation)

I've read a lot of SO questions on this and migration guides and api and am not clear. Most of the answers assume you have models and tables for the two entities. I'm starting from scratch so need a full solution. I have drugs and drug classes. …
0
votes
1 answer

Cakephp HABTM: Model not accessible in controller

I am trying to work with HABTM association between Profiles and Qualifications tables. Model: Profile.php App::uses('AppModel', 'Model'); class Profile extends AppModel { public $hasAndBelongsToMany = array( 'Qualifications' => array( …
i01000001
  • 119
  • 1
  • 2
  • 9