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 get roles color and more

I'm trying to make a RBAC in my own forum software. For so far, the permissions work, but the problem is, when I want to add colors to usernames (what MyBB also has) something doesn't work and I don't understand it propperly. So I have an…
Robin
  • 1,567
  • 3
  • 25
  • 67
0
votes
1 answer

Setting a relationship between Users to access a resource

I'm teaching myself Rails and I'm trying to setup a collaboration relationship kind of like Github adds collaborators to projects. My models look like this: class Restaurant < ActiveRecord::Base has_many :employees has_many :users, through:…
0
votes
1 answer

Rails - Form HABTM

I am new to Rails but I am stuck. I would like to create a form that will add data to two tables (books and books_authors). My view looks like: <%= form_for :book, url: book_path do |f| %>

<%= f.label :title %> :
<%= f.text_field :title…

mike927
  • 682
  • 1
  • 8
  • 25
0
votes
1 answer

find() on has_and_belongs_to_many not returning associations

I have a has_and_belongs_to_many relationship: class Staff < ActiveRecord::Base has_and_belongs_to_many :services class Service < ActiveRecord::Base has_and_belongs_to_many :staffs and I have a table called 'services_staffs' with columns…
99miles
  • 10,942
  • 18
  • 78
  • 123
0
votes
1 answer

Active Record Associations: has_and_belongs_to_many, has_many :through or polymorphic association?

The Ruby on Rails app I am working on allows users to create and share agendas with other users. In addition, we must be able to: Display a list of agendas for each user, on his profile Display a list of users associated with an agenda, on the…
0
votes
1 answer

using searchlogic with habtm associations

I have the following issue: I have two classes in my rails app, joined by a HABTM association, like so: #ad.rb has_and_belongs_to_many :specs #spec.rb has_and_belongs_to_many :ads joined by an ads_specs table. I'm trying to perform a search on the…
alex.g
  • 187
  • 1
  • 7
0
votes
1 answer

HABTM creating all records CakePHP

data CakePHP: Array ( [Table_1] => Array ( [name] => Test ) [Table_2] => Array ( [0] => Array ( [name] => Test ) [1] => Array ( [name] => Test ) ) ) SQL: CREATE TABLE…
paulorwd
  • 13
  • 3
0
votes
1 answer

How to setup multiple HABTM relationships between two tables in CakePHP

I'm trying to make two HABTM relationships between these two tables in CAKEPHP 2.6, but it gives me a database error when I try to create a record. I'm sure there must be some model settings or something, but I could not fix it. :( Here's an img of…
0
votes
3 answers

CakePHP HABTM Select box in edit mode not populating

I feel like I'm going insane. Usually I can figure these things out but this one has be truly stuck. I'm using Cake 2.3.7. I noticed there is a bug in earlier versions of CakePHP. Hope someone can point out where I'm going wrong. On my site I have…
0
votes
1 answer

Rails - HABTM find or create nested form

I found this. My question is now how do I create the form, I am trying: #students.row = f.fields_for :classrooms_students, f.object.classrooms_students do |cs| = cs.fields_for :student, cs.object.student do |s| …
sites
  • 21,417
  • 17
  • 87
  • 146
0
votes
1 answer

Translating query involving join table from CakePHP 1.3 to 3

I'm migrating an application from Cake 1.3 to 3.0. My database has teams and people (with teams_people to connect them via belongsToMany relations) and divisions (teams belongTo divisions). The teams_people table has additional information, like…
Greg Schmidt
  • 5,010
  • 2
  • 14
  • 35
0
votes
0 answers

Rails 4 HABTM (has_and_belongs_to_many)

First of all, I am totally new to rails.. I started to hack a rest Api together with the goal to consume it with ember-cli. I have 2 entities, books and authors. I use the has_and_belongs_to_many relationship. Exactly like this I can save books and…
0
votes
2 answers

How to show associated data in add form in cakephp 3.x

I have two tables CREATE TABLE `user_roles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `role_name` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=latin1 CREATE TABLE `users` ( `id` int(11)…
Sivabalan
  • 971
  • 2
  • 18
  • 43
0
votes
2 answers

Two or more Many to Many relationships between two tables in rails

I have two tables: Users and Groups a User has_many groups and a group, has_many a users: u = User.last u.groups g = Group.last g.users Supposed I wanted a second list of different groups, for some strange reason. Where once again a User has may…
JZ.
  • 21,147
  • 32
  • 115
  • 192
0
votes
0 answers

CakePHP HABTM table won't insert data with existing key

I have a problem with my HABTM table. This is the model structure: Team <- EmployeesTeam -> EmployeesAdditionalData 'EmployeesSecondary' => array( 'className' => 'EmployeesAdditionalData', 'joinTable' => 'employees_teams', 'foreign_key'…
Tony
  • 11
  • 5