Displaying 20 results from an estimated 20000 matches similar to: "noob question on deleting from join tables"
2006 May 06
3
Storing additional data on join tables with Rails
Hi there
I need to store additional attributes on join table. Searching the
Wiki [1] revealed two possible methods:
1) push_with_attributes, as described by Justin Palmer [2].
Unfortunately, "this method is now deprecated" [3]. Even if it wasn''t,
there seem to be inherent problems with that approach, for example
with updating those additional attributes, though Joshua Muheim
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 Dec 31
6
habtm recursion via destroy_without_callbacks
I am having a problem with two models that each have a HABTM
relationship to the other. For example:
CREATE TABLE people (id INT, name TEXT);
CREATE TABLE teams (id INT, name TEXT);
CREATE TABLE people_teams (person_id INT, team_id INT);
The person model has:
has_and_belongs_to_many :teams
And the team model has:
has_and_belongs_to_many :people
The trouble comes when trying to destroy
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 Aug 16
1
Naming rights_roles join model using has_many :through and polymorphic associations
Hi.
I have a couple of best practices questions regarding polymorphic
associations, naming join tables and user permissions.
Currently I have implemented the user authentication model from the
rails recipes book. Basically it goes something like this:
MODEL CLASSES:
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
end
class Role < ActiveRecord::Base
2006 Mar 31
6
Adding objects to a :through association
So I''m one of those nasty people building a self-referential
habtm-like Association using the funky new :through stuff. This is
about users having friends, so here''s my user.rb:
class User < ActiveRecord::Base
has_many :friendships, :foreign_key => ''user_id''
has_many :friends, :through => :friendships, :source => :friend
end
And here''s
2006 Jan 06
6
HABTM problem not saving all associations
Hello all,
I have an Order object that has and belongs to many Products and has
and belongs to many Loan Types. This is so I can select multiples of
each in my order entry screen via checkbox groups.
I''m having some trouble with saving multiple HABTM associations for a
single model object; only the first HABTM association declared in the
model will save during the initial @order.save
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 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...
2006 Apr 29
5
HABTM - how to insert join row when associated rows exist
I have successfully used HABTM to create a many-to-one-to-many set of
rows in one step. Now, if two objects I want to associate already exist,
how do I create the join row? The Agile book mentions the
''push_with_attributes'' method. The text says this method is useful for
adding additional attributes to the join row (in the example a ''read_at''
timestamp). I
2006 Apr 20
2
Additional Fields in a Join Table
Hi,
I am creating an order management web application, and have run into an
issue over join tables. I am reading Agile Web Development and it says
that I can put additional fields within my join tables, and they give
the example of a date field.
I want to know if it is possible to do the following:
I have an orders table with the order information as well as an
orders_items table and an
2006 Jun 22
2
id column for join table... kosher?
I''ve got two tables, bookmarks & tags. Using a
has_and_belongs_to_many association, I can do lookups using a join
table called bookmarks_tags. Two questions:
1. Can I have a migration for my join tables? Rails seems to "know"
about join tables implicitly from the associations, but if I do a
rake migrate the join tables won''t be built. I''ve been
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 Jun 20
1
Preventing Dups in HABTM
I have a habtm that looks like:
report
has_and_belongs_to_many :subscribers
subscriber
has_and_belongs_to_many :reports
When I add a report to a subscriber, I have to run code like:
raise "already there, idiot!" unless
report.subscribers.find_by_id(subscriber_id).nil?
Is there a better way to avoid adding duplicative associations? has_many
:through seems like overkill for this
2006 May 17
2
Association data clobbering (foreign keys too?)
Can someone please confirm or correct the following statements?
If I have the following tables
create table as (id int, [...], b_id int);
create table bs (id int, [...], a_id int);
create table as_bs (a_id int, b_id int);
and the associations woould be defined like this
class A << ...
habtm :bs
belongs_to :b
end
so my Model A has a habtm collection of Bs *plus* a direct
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 Apr 05
4
Self-referential join creation/deletion and :through
Greetings.
First, this example is just my way of exploring :through. It probably
doesn''t need has_many :through, and could just use a standard HABTM
association.
Here''s the models:
class CourseRequisite < ActiveRecord::Base
belongs_to :requisite, :class_name => ''Course'', :foreign_key =>
''requisite_id''
belongs_to :course,
2006 Jun 26
2
n-way has_mant :through
I''m trying to setup some mildly complex associations for a project we''re
working on and can''t seem to find much documentation on n-way has_many
:through associations.
I have the following models: Person, PhysicalAddress, EmailAddress,
PhoneNumber.
Each person can have multiple PhysicalAddresses, EmailAddresses, and
PhoneNumbers, and multiple people can share the same
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 Jun 10
3
Weird Problem With Active Record
Is it me or is my model getting the created_at from the wrong model!
I have a HABTM relationship between Problems and Tags. In one of my
controller I do the following:
def view
@tag = Tag.find_by_name @params[:id]
end
In my view I do this:
<% @tag.problems.each do |problem| %>
...
<%= problem.created_at %>
...
<% end %>
Now, how come the created_at