All Questions
Tagged with ruby-on-rails has-and-belongs-to-many
701
questions
0
votes
0
answers
34
views
HABTM relationship / validates associated: valid? is true even though I don't think it is
I made the following join table to be used in a HABTM relationship between tasks and itself:
create_table :tasks_tasks, id: false do |t|
t.belongs_to(
:dropoff_task,
null: false,
...
-1
votes
1
answer
127
views
for has_and_belongs_to_many table name should be in singular or plural
for has_many we will use plural definitely
for belongs_to we will use singular
for ex:
has_many :users
belongs_to: user
But for has_and_belongs_to_many
has_and_belongs_to_many :user, join_table: :...
0
votes
1
answer
38
views
Ruby on Rails: Many-to-many relationship on the same table as a one-to-many relationship
I am learning Ruby on Rails and am currently struggling to implement a many-to-many relationship.
I have a user and a carpool that can be driven by a user and ridden by multiple users. So, I am trying ...
1
vote
0
answers
32
views
how to eager load a has_and_belongs_to_many association in mongoid?
I have a habtm association in a rails app using mongo / mongoid
class A
has_and_belongs_to_many :bs, inverse_of: :as
end
class B
has_and_belongs_to_many :as, inverse_of: :bs
end
and i want ...
0
votes
2
answers
54
views
I am trying to render only those items that belong to another controller in React
I am working on a travel planning web app project in Rails and Ract.
In my Ruby on Rails backend I have a model Place that belongs to my model Trip. in React.js on the frontend I am trying to render ...
-1
votes
2
answers
438
views
How to deal with 2 different type of associations with same table in rails?
I am creating my first rails application and stuck at this point for a long time.
So I have two models in my project.
Users (created through devise gem)
Projects
There are two associations of these ...
0
votes
1
answer
81
views
Get items with Rails relations
I have two models with a relation like this:
class Ticket < ActiveRecord::Base
belongs_to :group
end
class User < ActiveRecord::Base
has_and_belongs_to_many :groups
has_many :tickets, as: :...
0
votes
1
answer
217
views
Rails model custom validation having one type of association
I have a model User which have has_and_belongs_to_many associations.
app/models/user.rb
has_and_belongs_to_many :advisors, dependent: :destroy
has_and_belongs_to_many :teams, dependent: :destroy
I ...
0
votes
2
answers
127
views
How to share a Rails model with other Devise users in read-only mode?
In a Rails 5 application, I have a shortlist model in a HABTM relationship with a user model, with the users controlled by Devise. This is all working as expected, where each User can see their own ...
0
votes
2
answers
175
views
Rails migrations: many-to-many relationship between the same class | Interpersonal Relationships
I want to connect two People with the help of Relationship.
Person:
* id
* name
Relationship:
* person_a_id
* person_b_id
* connection # an enum with values like "colleagues", "friends&...
1
vote
1
answer
41
views
How to do a query on has_and_belongs_to in Rails with AND across the join instead of OR?
This may be a simple issue but I'm struggling. Here's what I'm trying to do:
I have a class, let's call it Car that HABTM Features. So:
class Car < ApplicationRecord
has_and_belongs_to_many :...
0
votes
2
answers
66
views
Has_and_belong_to_many association
I have two models with no associations between them. So, I generated a migration and added an association.
class Post < ActiveRecord::Base
has_and_belongs_to_many :workspaces
end
class Workspace ...
0
votes
1
answer
22
views
Ruby HABTM association loop
i want to achieve a nested loop without duplicates in a have and belongs to many relationship
i have a model 'campaign' and for each campaign i also have campaign data.
i want to display each campaign ...
0
votes
1
answer
45
views
Has_many through has_many relation issue in rails
In my gaming project I have defined couple of models:
class Ticket
belongs_to :user
belongs_to :game
has_and_belongs_to_many :payments, join_table: 'tickets_payments',
...
4
votes
1
answer
264
views
Has and belongs to many API updates
I have a has_and_belongs_to_many in my Rails project. The schema look like this
create_table :dogs do |t|
t.string :name
t.string :breed
t.string :dog_type
end
...