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

Laravel how to use BelongsToMany

I am confuse to use belongstomany in laravel. following is my code. users.php public function guser() { return $this- >belongsToMany(User::class,'reportings','user_id','reporting'); } SQL TABLEs REPORTING TABLE: ID USER_ID …
Muhammad Kazim
  • 611
  • 2
  • 11
  • 26
0
votes
1 answer

Trying to remove a has_and_belongs_to_many relationship in rails

So I just started my first rails project yesterday. I had two many-to-many (has_and_belongs_to_many) relationships in my application. I had one between models games and teams and another between models stats and results. This was all working just…
Jack
0
votes
0 answers

CakePHP 2.X Order on Field in HABTM Join Table

I have these 3 tables: cols groups | id | ... | ... groups_users | group_id | user_id | created users | id | ... | ... In my Group model, I have a HABTM relation with the User model (using the alias…
bowlerae
  • 924
  • 1
  • 14
  • 37
0
votes
1 answer

Rails HABTM with join table get non associated records

I am using Rails 5 with postgresql 9.6. I have the following model and relationships Tables people segments people_segments (join table) Relationships person: has_and_belongs_to_many :segments, through: :people_segments…
0
votes
1 answer

Need to display the specialization that are not selected by the current user, to access HABTM join_table

I need to display the Specialization that are not selected. User has_and_belongs_to_many specializations and Specialization has_and_belongs_to_many user. Is there any possible to display the specializations that are not selected by the current…
Thananjaya S
  • 1,451
  • 4
  • 18
  • 31
0
votes
1 answer

Rails 3: habtm migration, primary key issue

I'm trying to setup a migration file for a habtm relationship, however when I run the migration I'm getting the following error: Primary key is not allowed in a has_and_belongs_to_many join table (parts_vehicles). Here is my migration file…
Brian Wigginton
  • 2,632
  • 3
  • 21
  • 28
0
votes
1 answer

Rails 3, using has_many through and polymorphism, or something else?

I have a problem that I can't solve. The problem is that I've got one user-model, and one event-model and in the event model a user can have multiple role's. We can also add attendants either an existing user, or create a fake user that can be…
0
votes
2 answers

Has and belongs to many - display all records in table view

I have a model called Patient and table patients This model Patient represents a patient in a doctor's office. I have a model for gender populated with different gender names Patient has_and_belongs_to_many :genders and Gender…
mike9182
  • 269
  • 1
  • 3
  • 17
0
votes
1 answer

Rails - Connecting checkboxes to change values for a join table

I have two models Events and Interests which are connected by a join table migration EventsInterests (event_id, interest_id, id=>false). I was trying to create something where you could connect a set of interest categories to some events within my…
ChrisWesAllen
  • 4,935
  • 18
  • 58
  • 83
0
votes
1 answer

Joins not used for complex HABTM search CakePhp 2

I have Contents, which can have Tags belonging to different TagGroups. I have a quite complex search condition which is as follows: A Content matches if it is tagged with at least one tag from the search as long as it belongs to the same tag group.…
Calamity Jane
  • 2,189
  • 5
  • 36
  • 68
0
votes
1 answer

Complex Associations - CakePHP 3.x [ Nested belongsToMany]

I have a complex joining like A belongs to Many B threw AB table AB belongs to many C threw ABC table Now my problem is how i can get data in controller A which contain result till table ABC. Not finding direct relation in A and table ABC My…
Sandeep K.
  • 21
  • 5
0
votes
1 answer

correct data array to save with this kind of relationship

class Post extends AppModel { var $name = 'Post'; var $hasMany = array( 'CategoryPost' => array( 'className' => 'CategoryPost' ) ); var $belongsTo = array( 'Page' => array( 'className'…
Teej
  • 12,764
  • 9
  • 72
  • 93
0
votes
1 answer

How to get HABTM associated data using hasOne binding

I am following example documented at http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM I am trying to retrieve associated data using hasOne. I created 3 tables posts, tags and posts_tags. I wrote following code to debug…
Mosu
  • 51
  • 1
  • 4
0
votes
3 answers

SQLSTATE[42S02]: Base table or view not found (belongsToMany) Laravel 5.4

Please someone help me on this. I am new to laravel and now I need to store an array from a select tag to mysql and I am having this erorr. SQLSTATE[42S02]: Base table or view not found: 1146 Table 'cmsystem.account_code_project' doesn't exist (SQL:…
kalawadei
  • 25
  • 1
  • 7
0
votes
3 answers

Rails HABTM reading unique records

Here is what i have. client has_many branches branch has_many projects project has_and_belongs_to_many announcements Is there an easier way to find the announcements given a client? I need a unique collection of announcements.
AMIT
  • 539
  • 1
  • 4
  • 13