has-and-belongs-to-many Questions
5
I have two models, users and promotions. The idea is that a promotion can have many users, and a user can have many promotions.
class User < ActiveRecord::Base
has_and_belongs_to_many :promoti...
Nichani asked 29/4, 2010 at 19:10
7
Solved
How do I do a script/generate migration to create a join table for a has_and_belongs_to_many relationship?
The application runs on Rails 2.3.2, but I also have Rails 3.0.3 installed.
Evacuate asked 7/12, 2010 at 20:18
4
Solved
I have two models, Users and Leads connected with HABTM relation:
class Lead < ActiveRecord::Base
has_and_belongs_to_many :users
end
class User < ActiveRecord::Base
has_and_belongs_to_man...
Chrysalid asked 26/2, 2014 at 21:38
3
Solved
I have 2 models:
class User < ActiveRecord::Base
has_and_belongs_to_many :groups
end
class Group < ActiveRecord::Base
has_and_belongs_to_many :users
end
I want to make a scope (that's i...
Morra asked 11/8, 2011 at 20:11
2
I'm working in a legacy Rails app that has been diligently upgraded with each major version of Rails and we're currently on rails 5.1 and I can't get a before_destroy to prevent the deletion if it ...
Hermaphroditism asked 28/6, 2018 at 2:29
4
Solved
I have next 'member_companies' table in DB:
And in model Member has a relation :
public function companies()
{
return $this->belongsToMany(Company::class, 'member_companies');
}
And it re...
Apollyon asked 11/4, 2019 at 13:18
4
I have Accounts and AccountAddressess. An account can have many AccountAddressess and I would like to specify one as the "default_account_address", so in the Account table, I have a column named "d...
Circassia asked 6/4, 2011 at 18:37
4
Solved
I've found an old plugin called acts_as_habtm_list - but it's for Rails 1.0.0.
Is this functionality built in acts_as_list now? I can't seem to find any information on it.
Basically, I have an ar...
Conjugate asked 16/2, 2010 at 17:35
2
Edit #2
Here is the courses controller
class CoursesController < ApplicationController
layout proc { user_signed_in? ? "dashboard" : "application" }
before_action :set_course, only: [:show,...
Susurration asked 22/8, 2018 at 17:26
11
Solved
Given the following
class User < ActiveRecord::Base
has_and_belongs_to_many :companies
end
class Company < ActiveRecord::Base
has_and_belongs_to_many :users
end
how do you define factor...
Smatter asked 27/9, 2009 at 20:17
3
Solved
Is it true that HABTM relationships do not support the :dependent option?
class Person < ActiveRecord::Base
has_and_belongs_to_many :posts, :dependent => :destroy
end
I am trying rails ed...
Brainsick asked 10/5, 2010 at 0:33
3
Solved
What I mean is if I have two models, connected by a has_and_belongs_to_many association, can I store other data in the join table for each association? That is, the extra data would not be part of ...
Oakie asked 23/2, 2012 at 0:58
1
I have two tables: categories and videos, I then have a pivot table for these as it's a belongsToMany relationship.
What I'm trying to do is get all of the videos where there isn't a single instan...
Repeater asked 6/5, 2017 at 14:7
3
I have Page and Paragraph models with a has_and_belongs_to_many relation. Given a paragraph_id, I'd like to get all matching pages. e.g.:
pages = Paragraph.find(paragraph_id).pages.all
However, ...
Numinous asked 29/11, 2012 at 11:49
1
Solved
I have two ActiveRecord models having a HABTM relationship with eachother.
When I add an AccessUnit through a form that allows zones to be added by checking checkboxes I get an exception that the A...
Bullheaded asked 17/11, 2016 at 21:8
1
I`ve got a model with several taxonomies using acts-as-taggable-on
class Film < ActiveRecord::Base
attr_accessible :mood_list, :genre_list, :tag_list, :country_list
acts_as_taggable_on :count...
Barnwell asked 17/10, 2013 at 8:18
3
Solved
I use CakePHP 2.2.2
I have 3 tables: restaurants, kitchens and kitchens_restaurants - join table for HABTM.
In Restaurant model I have:
public $hasAndBelongsToMany = array(
'Kitchen' =>
arr...
Deerstalker asked 16/9, 2012 at 21:2
4
Solved
I have two models with a HABTM relationship - User and Role.
user - has_and_belongs_to_many :roles
role - belongs_to :user
I want to add a uniqueness constraint in the join (users_roles table) ...
Shawnna asked 14/2, 2011 at 3:38
2
Solved
How do you remove a HABTM associated item without deleting the item itself?
For example, say I have 3 Students that are in a Science class together. How do I remove the Science objects from the St...
Bandurria asked 7/7, 2009 at 0:53
2
Solved
Although the code seems to be right, when I try to send the form, the values of the multiple select aren't being sent.
If I just remove the multiple option, everything works as expected considerin...
Shot asked 18/7, 2013 at 21:25
2
Solved
Let's say I have an association where User has and belongs to many Roles. When I destroy the user, is the record in the join table automatically removed as well? Or do I need to use :dependent => :...
Fid asked 16/2, 2011 at 17:4
4
Solved
I have two models restaurant and user that I want to perform a has_and_belongs_to_many relationship.
I have already gone into the model files and added the has_and_belongs_to_many :restaurants and...
Boehmite asked 3/7, 2011 at 5:50
1
Solved
I have a HABTM relation like : Post <-> Tag (a Post can have multiple Tag, and same the other way).
This work with the multiple checkbox selection generated by Cakephp. But I want to have a...
Prettypretty asked 11/1, 2016 at 13:57
2
Solved
Equipment.create(name: "Room to run")
Equipment.create(name: "Pull-up bar")
Workout.create(
description: "Do 100 pull-ups then run 5km",
:equipment => Equipment.where(:name => 'Pull-up bar'...
Deathtrap asked 7/7, 2012 at 19:14
2
Recently I ran into mystical bug with rails 4 and HABTM relation.
first of all my Gemfile:
source 'https://rubygems.org'
gem 'rails', '~> 4.1.6'
gem 'pg'
Next. my Models:
class User < Act...
Gasteropod asked 22/10, 2014 at 12:5
1 Next >
© 2022 - 2024 — McMap. All rights reserved.