has-and-belongs-to-many Questions
1
Solved
With Rails 3.1.3 on Ruby 1.9.2, I have:
class User < ActiveRecord::Base
has_and_belongs_to_many :states
end
class State < ActiveRecord::Base
has_and_belongs_to_many :users
end
A User is...
Selfsown asked 14/12, 2011 at 8:55
4
Solved
Bounty:
+500 rep bounty to a GOOD solution. I've seriously banged my head against this wall for 2 weeks now, and am ready for help.
Tables/Models (simplified to show associations)
nodes
id
nam...
Brooklyn asked 1/9, 2012 at 3:11
3
Solved
I have two tables: "restaurants" and "cuisines" which are related to each other by a HABTM table
The table cuisines has certain fixed entries - 54 number
A restaurant can have any number of cuisi...
Cormac asked 12/8, 2009 at 16:23
1
Solved
I am a rails noob so the below is probably down to lack of understanding however I have been looking/reading all day and cannot seem to find the solution.
I have two models - project and technolog...
Hairdo asked 12/8, 2012 at 19:17
6
Solved
What is the method to save and update Many to Many relationship in Yii framework?
Gannes asked 26/9, 2009 at 13:26
1
I have 2 models (Workout, Equipment) in a has and belongs to many relationship. If I use Workout.find(:all, :joins => :equipment, :conditions => "equipment.id = 5") it works, but if I use Wor...
Jonis asked 1/7, 2012 at 3:23
3
Solved
Spent all day on Google, but can't find an answer. :\
I have a HABTM relationship between Users and Core_Values.
class CoreValue < ActiveRecord::Base
has_and_belongs_to_many :users
class Use...
Psychoneurotic asked 19/1, 2011 at 0:13
1
Solved
I am new to rails, and am trying to set up a many-to-many relationship in my rails project. I have a small strategy, but I am not sure if its the correct way.
Aim:
I have a table of users, and a t...
Obrian asked 21/4, 2012 at 13:59
1
Solved
Mongoid ships with .push on a habtm, which sets a habtm relationship in both directions. Although delete will #delete an associated record, there's no documented way to delete only a relationship t...
Commie asked 20/12, 2011 at 19:25
3
I have two tables with a many to many relationship that I am using has_and_belongs_to_many to define the association.
class Foo < ActiveRecord::Base
...
has_and_belongs_to_many :bar
...
end
...
Lucrece asked 22/10, 2010 at 14:38
1
Solved
I'm writing a blog engine in rails, and have set up a tag model and a post model which have a have_and_belongs_to_many relationship. Tag addition works fine, the problem comes when looking for all ...
Barbiturism asked 11/8, 2011 at 19:4
2
Solved
I'm quite new to this and I'm using cancan + devise for my user auth. However I'm not really sure what it means to set up a typical users HABTM roles relationship nor do I really understand what a ...
Akin asked 14/7, 2011 at 6:57
4
Solved
I have two tables, with a HABTM relationship in Rails. Something like the following:
class Foo < ActiveRecord::Base
has_and_belongs_to_many :bars
end
class Bar < ActiveRecord::Base
has_and...
Dorchester asked 4/2, 2010 at 21:37
3
Solved
class Company
has_and_belongs_to_many :users
end
class User
has_and_belongs_to_many :companies
end
when i delete a company, what's the best (recommended) way to delete ONLY the associations of...
Waldgrave asked 14/2, 2011 at 15:57
4
Solved
Is there anything explicitly wrong with using has_and_belongs_to_many associations in rails instead of has_many :through? I'm aware of these articles describing differences and work arounds, but th...
Registry asked 18/3, 2009 at 13:16
5
Solved
Tables
restaurants
cuisines
cuisines_restaurants
Both restaurant and cuisine model are set up to HABTM each other.
I'm trying to get a paginated list of restaurants where Cuisine.name = 'italia...
Werra asked 13/4, 2011 at 21:35
2
Solved
I think this is really basic but I'm horrible with SQL so I have no idea how to do it...
I have a standard HABTM relationship between two models, LandUse and Photo. So I have a land_uses_photos jo...
Acevedo asked 5/4, 2011 at 16:22
2
Solved
I've got a model setup like the following:
class User
has_many :items
has_many :words, :through => :items
end
class Item
belongs_to :user
belongs_to :word
default_scope where(:active =&g...
Presidency asked 28/3, 2011 at 18:28
1
Solved
Is there a way to add callbacks for when an item is added to a habtm relationship?
For example, I have the following two models, User and Role:
# user.rb
class User; has_and_belongs_to_many :role...
Capello asked 11/3, 2011 at 2:34
4
I'm working on a CakePHP 1.2 application. I have a model "User" defined with a few HABTM relationships with other tables through a join table.
I'm now tasked with finding User information based on...
Uzia asked 29/11, 2008 at 2:18
2
Solved
Hi i'm using a has_and_belongs_to_many in a model.
I want set the valitor of presence for kinds.
and set the max number of kinds per core to 3
class Core < ActiveRecord::Base
has_and_belongs_...
Sulfanilamide asked 28/1, 2010 at 21:41
2
Solved
I'm teaching myself Rails, and as a test project I'm mocking up a simple question/answer app similar to stackoverflow.
In my simplified version I have:
questions
answers
users (the authors of ques...
Lashio asked 13/1, 2010 at 5:52
1
Solved
I'm using cakephp and would like to display all Submissions which are part of Category 'X'
I have 4 tables with a HABTM relationship.
Users -> (haveMany) -> Submissions <-> (hasAndBelongsToMany...
Creamcolored asked 26/12, 2009 at 12:42
2
Solved
Through many iterations of testing, I just noticed that my join table that represents a HABTM relationship between two models isn't removing entries when instances of these models get deleted. Do I...
Spoofery asked 16/12, 2009 at 15:8
1
Solved
I am learning RoR and trying to use accepts_nested_attributes_for and has_and_belongs_to_many to submit information that would traditionally be two forms. I have read on some sites they are compati...
Halfhour asked 4/12, 2009 at 15:21
© 2022 - 2024 — McMap. All rights reserved.