Displaying 20 results from an estimated 20000 matches similar to: "habtm with acts_as_list vs. :through"
2007 Jun 14
1
HABTM and acts_as_list
I don''t think this needs much explanation. Is what I''m trying to do
even possible?
class CreateLanguagesProducts < ActiveRecord::Migration
create_table languages_products do |t|
t.column :language_id, :integer
t.column :product_id, :integer
t.column :language_position, :integer
end
end
class Language < ActiveRecord::Base
acts_as_list :scope =>
2006 May 18
3
Model Madness: habtm vs through
This has me scratching my head:
a Person has many Things
a Person has many Collections
a Collection has many Things
...Things in a Collection are ordered
...Things in a Collection can be related to (created by) any User
...a collection has additional attributes, such as a name etc
I am confused about habtm in rails (especially when using
acts_as_habtm_list) vs. going the :through route.
2005 Jun 03
1
sorting on a habtm relationship
I have two tables ("products" and "categories") that have a
has_and_belongs_to_many relationship, and I need to be able to
arbitrarily sort products in the scope of a category using something
like acts_as_list. Problem is, since each product can belong to
multiple categories, it doesn''t work to use acts_as_list and have the
"position" field be in the
2006 Mar 22
10
Need for multiple acts_as_list
I have a model "Childmodel" that belongs_to two other models "Parent1"
and "Parent2". "Parent1" "has_many :childmodels, :order => :positionp1"
and "Parent2" "has_many :childmodels, :order => :positionp2". i.e. The
child is independently positioned within each of its parents.
This works fine and gets me the useful
2006 Jan 19
5
Multiple HABTM relationships with self ???
I need to have a table related to itself via a join table. Will HABTM
support this? That is:
class Recipe < ActiveRecord::Base
has_and_belongs_to_many :recipes, :join_table => "recipes_recipes"
end
More importantly -- how does RoR support MULTIPLE self-joins? I.e., to
relate the table to itself via multiple join tables.
SFAIK, HABTM won''t support multiple
2006 Feb 19
4
Multiple HABTM to one table
I have a class Player, and a class Game.
Game has two HABTM relationships to the Player table through seperate
relationship tables.
class Game < ActiveRecord::Base
has_and_belongs_to_many :players, :uniq => true
has_and_belongs_to_many :victors, :class_name => ''Player'', :uniq => true
end
When I add Player A to players, and Player B to victors, and save the
2007 Oct 15
0
converting from HABTM to has_many :through
Hello,
I have a has_and_belongs_to_many relationship that I''ve realized I need
to add additional attributes to. So I''m converting it to a has_many
:through (HMT) relationship. This is the first time I''ve used an HMT,
and it seems like I''m using too much code. I couldn''t figure out how to
get the join model objects to update automatically as a result of
2006 Jan 03
0
habtm and insert_sql
Briefly, I want to create an :insert_sql attribute for
a has_and_belongs_to_many relationship, and then add items to that
relationship using push_with_attributes. Is that possible?
Less briefly:
I have a legacy postgresql database where one of the join tables has an
ID column, so I had to set up the association with a custom :finder_sql
attribute, as follows:
class Topic <
2006 Feb 20
0
No Magic for HABTM forms?
Hi,
I posted yesterday asking how to get form tags to reference the
associated objects in a habtm relationship. I was hoping for Rails
Magic, but it looks like Rails doesn''t have habtm magic beyond a
certain point.
Here was my solution for others who might have the problem. Also, I
hope someone shows me that there is a simpler way.
The Database Model:
class Registration <
2006 Jan 15
2
acts_as_tree & acts_as_list for a single model?
Hi,
If I have a db table
categories
- id
- name
- parent_id
- position
is it alright to have the Category model act_as_tree and for each
level act_as_list?
class Category < ActiveRecord::Base
acts_as_tree :order => :position
acts_as_list :scope => :parent_id
end
Thanks,
Peter
2005 Dec 15
2
HABTM being tricky
I''ve just been bodyslammed by a problem with has_and_belongs_to_many -
as far as I can tell, if it doesn''t appear at the top of other
relationship definitions it doesn''t seem to work right. For example:
class Artist < ActiveRecord::Base
has_and_belongs_to_many :genres
has_many :albums
has_many :videos
has_many :cds
has_many :collections
end
..works fine
2008 Jan 15
0
HABTM acting as list on Rails 2
Hi Fellow Railworkers
Now that Rails 2 is the engine, is there an easier way to have a HABTM
relation act_as_list?
The solution outlined in the wiki is pretty ugly:
http://wiki.rubyonrails.org/rails/pages/HowToUseActsAsListWithHasAndBelongsToMany
Thanks for any hints, -sven
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this
2005 Dec 16
0
Join table with acts_as_list?
If anyone can point me in the right direction, I''d appreciate it.
I thought I''d recently seen an example of a habtm relationship where
the join table used an acts_as_list to keep the ordering of the
relationship. Does anyone have a slick way of doing this in 1.0, or
was it something in edge rails that I''m thinking of? (The
new :through parameter maybe?)
2006 Mar 25
1
Nuby: HABTM and drag-and-drop views
I have two tables that have a HABTM relationship: Teacher
has_and_belongs_to_many Groups, and Group has_and_belongs_to_many
Teachers.
This is what I want: select a Teacher, and then drag Groups from one box
to another to assign them to the teacher. Or, select a group, and drag
and drop Teachers to assign them to groups. All using AJAX, (off
course).
Only problem is, I don''t know
2008 Dec 16
1
Callback when objects connect as a habtm relationship
If Product and Category models are in a habtm relationship, i.e.
class Product < ActiveRecord::Base
has_and_belongs_to_many :categories
end
class Category < ActiveRecord::Base
has_and_belongs_to_many :products
end
I want a piece of code to be executed every time a product is connected to a
category.
Where do I put this code? Which callback (and on which model) will be
triggered?
Any
2006 Mar 13
3
HABTM: two habtm''s between the same two tables
Imagine I want to track people, and the clubs that they belong to.
table people with columns person_id, person_name
table clubs with columns club_id, club_name
And I have the association table:
table clubs_people with columns person_id, club_id
Now I know how to do this habtm between the two, in order to associate
people with clubs that they belong to.
However my application also needs a
2005 Aug 11
0
No-brainer HABTM vs. select input question
Pardon my newbness.
I''m trying to create, populate, and save an object with an HABTM
mapping. That''s not working too well so far ;)
Assuming I have the mapping correct (HA!) and the db set up properly,
how do I create the select and options? I guess mostly I want to know
what I''m supposed to name it.
I have a FilingEvent class - HABTM State (both models have the
2006 Jun 30
2
how to HABTM with STI ??
Hello all
This is my first post so excuse the basic question. (and any repeats I just
got an email saying this post was too big so I have re-submitted a smaller
version)
I was following the thread on
http://lists.rubyonrails.org/pipermail/rails/2006-May/038988.html regarding
the STI on HABTM for RoR.
I have a very similar problem and was hoping for some help.
I have the
2006 Feb 28
8
HABTM count table
Hello,
I have a question about HABTM and counting records.
I have these models
class Sort < ActiveRecord::Base
has_and_belongs_to_many :reports
end
class Report < ActiveRecord::Base
has_and_belongs_to_many :region
has_and_belongs_to_many :subjects
has_and_belongs_to_many :sorts
end
And i would like to get a count like
@sort.reports.count
The problem is get this query:
2010 Aug 18
6
Once I added this HABTM, one of my 'through' relationships, on a non-habtm model, seems to have broke?
I''m a rails newb and have been Googling about this, but I''m still stumped.
Not showing everything here, but basically it should be a pretty common
setup so I''m sure others know what I''m doing wrong.
- A meter can belong to many meter_groups
- A meter_group can have many meters.
- A user can ''subscribe'' to viewing a meter_group (Subscription)