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 UndefinedTable: ERROR

I have two models, Clinician and Patient. A clinician has_many: patients and a patient belongs_to :clinician. A join table, shared_patients is meant to store additional associations between patients and clinicians as a patient can be shared by…
0
votes
2 answers

Using has_and_belongs_to_many to get list of associated objects rails

I have two models, Clinician and Patient. A clinician has_many: patients and a patient belongs_to :clinician. A third model, SharedPatient is meant to store additional assosiactions between patients and clinicians as a patient can be shared by…
Skiapex
  • 153
  • 3
  • 14
0
votes
0 answers

HABTM adding several players to team inserts only the first and updates that entry

I'm having a problem adding more than one player to a team. When I try to insert more than one player it only updates the first inserted entry which belongs to the team. But let's start at the beginning: When I call find on a team with several…
MrSmith
  • 370
  • 4
  • 22
0
votes
2 answers

Let a question always :include its author, how?

class Question < ActiveRecord::Base belongs_to :author end class Author < ActiveRecord::Base has_many :questions end When I find some questions, I usually need to get their authors at the same time, so I use: Question.find(:all,…
Freewind
  • 193,756
  • 157
  • 432
  • 708
0
votes
1 answer

Has many through stop printing the entire object after loop

I am practicing has_many through but I am stuck when the looping through the contents. It displays the whole object and not just the item want. Models: class Appointment < ActiveRecord::Base belongs_to :physician belongs_to :patient end class…
0
votes
0 answers

HABTM Rails - create method doesn't work

When I try to create some User with the POST below I received the following msg: Completed 404 Not Found in 17005ms (Views: 1.7ms | ActiveRecord: 6.6ms). I debugged a little and I find this error Couldn't find Shared::Category with ID=5 for…
DaniG
  • 108
  • 10
0
votes
1 answer

How to create a new child object and then create a has_and_belongs_to_many relationship with that child object in the same form

I'm new to rails and building a relational database application. I have a somewhat complex database structure, and am trying to create a nested form that creates a child object, and then associates that child object to existing objects through a…
0
votes
1 answer

Rails: uninitialized constant Model::RenamedAssociation when using class to specify model in relationship

I have 3 tables, Charges, Transactions and Charges_Transactions. I had to rename the associations on my models as there is an existing transactions method which was interfering with the association. See this article class Charge <…
Rumpleteaser
  • 4,142
  • 6
  • 39
  • 52
0
votes
3 answers

Does CakePHP treat all INT fields as ID's for join tables?

I am trying to save a User, their Profile, and some tags and my join table that links the profile and the tags keeps getting messed up. The profile model is called Instructor, the tag model is called Subject. The Instructor has a phone number and a…
user213811
0
votes
1 answer

CakePHP 3.0 saving belongsToMany without associated ID

I have People belongsToMany Phones. Can I save a person with its phone in one save() like this? in PeopleTable: $this->belongsToMany('Phones', [ 'foreignKey' => 'person_id', 'targetForeignKey' => 'phone_id', 'joinTable' =>…
leeroy
  • 1
  • 1
0
votes
2 answers

Using Rails, How can I join a join table with a join table?

I have a permissions model that is based on an individual Store. A store has a member that can view data has_and_belongs_to_many_users, edit data has_and_belongs_to_many_editors and own the Store has_and_belongs_to_many_owners. If I were to add…
JZ.
  • 21,147
  • 32
  • 115
  • 192
0
votes
3 answers

ActiveRecord: select record that meets a combination of HABTM

I have 3 tables/models Participants, Demographics, ParticipantDemographics. I would like to find Participants who have a combination of Demographics. Here is a simple example: Lets presume in some UI I am trying to filter a list of participants. I…
0
votes
1 answer

Param is missing or the value is empty don't take parameters, just id

I have a relation has_and_belongs_to_many with places and events. When i create a event dont save the places parameters but yes the others parameters. However, when i want to edit a event, this dont take the paremeters saved. (image) ¿what is the…
0
votes
1 answer

Cake 3 saving belongsToMany relation crashes

I currently have an belongsToMany relationship between two Table, Skus and Medias. I named the join table skus_images though. I'm here trying to save only ids, not inserting new data in an HABTM way. I have in my form : echo…
yachaka
  • 5,429
  • 1
  • 23
  • 35
0
votes
3 answers

Display all posts from a certain category

I'm looking to display all posts from a certain category on a page, I currently have Posts & Category models linked by a HABTM relationship. I want to be able to click the link on my index.html.erb and go through to a page that lists all the posts…
Jonathan
  • 673
  • 1
  • 10
  • 32