Displaying 20 results from an estimated 3000 matches similar to: "Newbie: HABTM problems"
2006 Jun 05
5
adding habtm through migrations
Hello,
I''m stuck, I''ve got a model Product and would like to add a new model
called Category. Furthermore, I want to set up a many2many
relationship between the mentioned models. the problem is that I do
not know how to set the primary key in the categories_products table.
this is what I''ve got in my migration file:
create_table :categories do |t|
t.column :name,
2006 Apr 05
5
Updating attributes in HABTM association
Hi,
I am trying to find a way tp update attributes in a habtm association. I
am trying to use the code from ticket #2462, but as my
association_class_primary_key_name seems to be empty the generated sql
code is corrupt. I hope thats not a problem of my model that this
variable is empty.
What would you recommend to update those attributes (rails 1.1)
THANKS!!!
--
Posted via
2006 Jul 05
7
HABTM join table has an "ID" column - is this an issue?
All,
I''m building model objects for existing tables that I cannot modify.
In AWDWR, Dave says "Note that our join table has no id column...The
second reason for not including an id column in the join table is that
AR automatically includes all columns from the join tables when
accessing rows using it. If the join table included a column called id,
its id would overwrite the id
2006 Jul 10
7
What is has_many :through really buying you over HABTM?
So having just learned how to do has_many :through as opposed to HABTM,
and then, being concerned that I wouldn''t get it to work, I started
thinking about these two approaches.
It seems to me that the _only_ problem that the HM:T (has_many :through)
approach solves that HABTM doesn''t is the issue of the potential
collision of id columns between your join table and one of
2006 May 23
2
HABTM for Dummies Question
Taking time off from programming is always painful :-).
I have the following Models:
====
class Tag < ActiveRecord::Base
has_and_belongs_to_many :problems
end
class Problem < ActiveRecord::Base
belongs_to :user
has_and_belongs_to_many :tags
end
====
And the following migrations:
====
create_table "problems" do |t|
t.column "user_id", :integer
2006 May 31
6
habtm on an array (or object.habtm.habtm)
Hi,
I have three Models: User, Group and File.
User habtm groups
and
Group habtm Files
How can I find all files that a particular user has access to?
eg user.groups.files ?
As user.groups returns an array, the above doesn''t work.
Id like to find the files for all groups in that array, without adding
any code to the User model.
Thanks in advance
PS I just posted this in the
2006 Jun 16
3
Does HABTM support non "id" FKs?
Quick question. Say I have a geographical database with counties and zip
codes where counties have and belong to many zip codes.
zip_codes (id, zip_code)
counties (id, name)
When I create the association table, the Rails way says to do the
following: counties_zip_codes (county_id, zip_code_id).
However, given that zip_codes.zip_code is itself a candidate key, I
would much prefer to do the
2006 Mar 28
3
Rails 1.1: Is HABTM obsolete?
Does the new has_many :through and belongs_to :through obsolete (well,
replace and essentially deprecate) has_and_belongs_to_many?
Joe
--
Posted via http://www.ruby-forum.com/.
2006 Jul 10
4
HABTM vs. using has_many :through
All,
I''ve heard recently about has_many :through as a necessary alternative
to HABTM (when the join table has it''s own id column, say, in a legacy
schema). However, is the prevailing Rails wisdom now that one should
use has_many :through in _all_ cases?
If so, why?
Thanks,
Wes
--
Posted via http://www.ruby-forum.com/.
2006 Apr 30
2
HABTM: Find sorted by number of associations
Hi,
I''ve been googling and searching the forums for some time
but can''t seem to find exactly what I''m looking for.
Suppose User HABTM Products (for example a favorites list). I would like to
construct a single query for finding Products ordered by the number of
Users that have flagged them as favorites.
Although I can construct the query using SQL a with a
2006 Aug 09
3
HABTM and getting to arrays from either direction
I didn''t find exactly an answer on this one, so I''d like to get a
clarification from folks who live & breathe HABTM.
class foo
has_and_belongs_to_many :bars
end
class bar
has_and_belongs_to_many :foos
end
(and yes, I have a bars_foos table in my db)
def test_habtm
bar = Bar.new
foo = Foo.new
foo.bars<<bar
assert !foo.bars.empty?
assert
2006 Jul 05
1
created_on in HABTM table getting parent dates
All of my HABTM tables receive the parent created_on/last_update_on
dates whenever a record is inserted into these join tables. I don''t
have any defaults in the database or anything else populating these
tables. I assumed rails would populate these automagically. Is there
something that needs to be done to get this to populate with the correct
current timestamp instead of
2006 Jul 12
1
odd habtm behavior? or is it me?
Hello List,
I''m a bit spent on this problem, and my code might be whack. I seem to be
encountering a problem where the primary key on a join table is not being
resolved correctly. I will elaborate after some code bits. I am creating
the join table using migrations, and relevant model code is this:
class Post < ActiveRecord::Base
has_and_belongs_to_many :records
2006 Jul 10
10
has_many :through and foreign key parameters
I just took my HABTM and turned it into a :through since my join table
has another "non-joiny" attribute.
I went from this:
has_many_and_belongs_to :jobs, :join_table => ''tablename'',
:foreign_key => ''x'',
:association_foreign_key => ''y''
to this:
has_many :jobs, :through =>
2006 Aug 07
4
multiple habtm joins on the same two tables
i have a taskmanager type of project that i am working on, where i need
to separate joins on the same two tables. i need one join for users that
are assigned to the task, and another join for who has read the task, so
they can tell which ones are new.
any suggestions on the best way to accomplish this?
thanks
--
Posted via http://www.ruby-forum.com/.
2006 Jun 11
2
HABTM Duplicates?
Hello all,
I''m working on a small Rails site for a game I play that will
be used to add new characters. Part of this addition process is choosing what
skills the character will have. For this, in MySQL, I have a characters table
and a skills table, as well as a characters_skills table that is used as the
join table in the habtm relationship between the two. I am presenting the
skills in
2006 Apr 16
6
still learning maintaining data with join tables
Class Role
has_and_belongs_to_many :users
Class User
has_and_belongs_to_many :roles
Class RolesUsers
has_and_belongs_to_many :roles
has_and_belongs_to_many :users
According to the logs...I''m good through here
@roles_users = RolesUsers.find(:all,
:conditions => ["user_id = ?", params[:users_id]] )
the next section of controller code is a problem...
2007 Sep 06
4
HABTM association with own class?
If I have a class, Asset, which has and belongs to many associated Asset
objects, how do I do this?
has_and_belongs_to_many :associated_assets, :class => "Asset",
:foreign_key => ?????, :association_foreign_key => ?????
Right now, my table has a :first_asset_id and a :second_asset_id, but I
don''t see how the objects themselves are supposed to distinguish one
from the
2006 May 16
4
Problems with multiple ''id'' columns in a join_table
I have a problem declaring a relationship through a join_table ; the SQL
generated by ActiveRecord is correct, but there are two columns called
''id'', and the final object gets the ''wrong'' column ...
Here''s a more detailed description of the data, code, and problem :-
There''s a People table, with id, name, and a few things.
Also a
2006 Apr 20
5
Using Migrations to convert join table to join model
Greetings,
I''m trying to convert a HABTM w/attributes join table in my database
into a join model table in order to utilize the new has_many :through
functionality introduced in Rails 1.1. Here''s the current table
definition:
licenses_user_groups: license_id, user_group_id, usage_notes
Perhaps it was a mistake, but I made (license_id, user_group_id) the
primary key.
Now,