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
2 answers

HABTM find with a condition

I have two tables which are related as HABTM: Groups(id, name) Streams(id, Stream) Connecting table: groups_streams(id, group_id, stream_id) There is another model called Users which HasOne Group. From the User controller I am trying to get the…
Harsha M V
  • 54,075
  • 125
  • 354
  • 529
0
votes
2 answers

Saving HABTM associated data in cakephp

I have a little problem. My Commodity model has Has and belongs to many association with User model. In the DB they are related through commodities_users table. So, I want Cakephp to create new records in commodities_users table in DB when the new…
handkock
  • 1,067
  • 2
  • 11
  • 23
0
votes
1 answer

Preserving join table data when reseeding a database

I'm reseeding a fairly large database with updated static data and updated values which users engage with. However, I've noticed that reseeding the database clears all join tables for Has_and_belongs_to_many tables (all other user data, and tables…
0
votes
4 answers

Could I same column to represent a foreign key to multiple tables?

I am trying to use the same column to represent a has foreign key to different columns. This is because there could be an arbitrary number of tables to be indexed using this column. Right now, my idea is to use a small varchar() field to represent…
chustar
  • 12,225
  • 24
  • 81
  • 119
0
votes
0 answers

NameError: uninitialized constant RequiredFields when doing a join_table

I am trying to do a join table. My first table is called web_forms with column account_id. Second table is called required_fields with column web_form_id. I am currently getting the error... RequiredFields.find(226) ActiveRecord::RecordNotFound:…
0
votes
1 answer

Rails display a list of has_and_belongs_to_many features for a given project

I have a has_and_belongs_to_many relationship between client "projects" and "features" that they selected through a collection_checkbox administered through a join table called projects_features. So: each user is able to create projects, and these…
Stephen
  • 187
  • 12
0
votes
1 answer

Why is HABTM generating queries that include an 'id' column?

I have a Role model and Permission model. The Role model: has_and_belongs_to_many :permissions The Permission model: has_and_belongs_to_many :roles The migration to create the permissions_roles table: class CreatePermissionsRoles <…
please delete me
0
votes
3 answers

How to insert data in join table based on HABTM association rails 4

I have created a HABTM association in refinery cms but it returns error like below: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "refinery_georgiantoast_restaurant_wines" does not exist LINE 5: WHERE a.attrelid…
0
votes
1 answer

searchkick search HABTM

How can I use https://github.com/ankane/searchkick to search both Users and Skills and return users with skills searched for. Most relevant result should reflect how many of the skills the User has. My Models look like this: class User <…
0
votes
1 answer

Rails Newby: Strong parameters in Rails 5 not letting specified parameter Through - HABTM

I'm new to rails, and I'm currently trying to develop an API based app using Rails 5, on one of my controllers I have a function to filter the allow parameters like so def provider_params params.require(:provider).permit(:name, :phone, :email,…
0
votes
1 answer

CakePHP 3.x - SUM() on ManyToMany

I am getting stuck on using SQL functions queries made in CakePHP 3 in combinations with associations. The situation is as follows: I have three tables, a 'products' table, an 'orders' table and a join table called 'orders_products'. In the index…
Roberto
  • 958
  • 13
  • 33
0
votes
1 answer

Can we have multiple join tables for the same pair of tables?

I have two tables: offers and tests. But I need to have three join tables like, offers_tests_1, offers_tests_2, and offers_tests_3. This is because of a business requirement that an offer can have three combinations (packages) of tests. Can we do…
user1575148
  • 561
  • 6
  • 28
0
votes
1 answer

ActiveRecord retrieve records in HABTM relationship that belong to array of associated records

Maintenance HABTM MaintenanceOrders Given an array of MaintenanceOrder ids: [1,2,3,4,5], how can I retrieve all the Maintenances associated with those MaintenanceOrders? Tried this: @paired_things = Maintenance.where(maintenance_order_id:…
0
votes
2 answers

Rails 4 - has_and_belongs_to_many assocation

I created a has_and_belongs_to_many association between users and projects so that a user would be able to join in on a project. The association table exists however, I am unsure how I would create the association. View Schema
Jon Cho
  • 11
  • 3
0
votes
1 answer

Don't select an habtm field in a find

I am here trying to improve one of my select. My model is as follows: Network --->hasMany Esx --->hasAndBelongToMany Environment A network might have 0 Esx and/or 0 environments So here I want to select some network information and the Esx section,…
Nicolas Barlogis
  • 199
  • 1
  • 1
  • 12