Displaying 20 results from an estimated 8000 matches similar to: "Habtm: I can create the same relation more than 1x!"
2006 Jan 29
9
Specify options with habtm
Hi all
I have the following models:
class member
has_and_belongs_to_many :disc_jockeys
end
class disc_jockey
has_and_belongs_to_many :members
end
The relation table is called disc_jockeys_members and has the following
fields:
disc_jockeys_members(disc_jockey_id, member_id, status)
So far, the field status can have values like valid, invalid, locked
etc., but it is not regarded yet by
2006 Feb 01
0
habtm and counter (xxx_count field in DB)
Hi all
I have the following models:
class Member < ActiveRecord::Base
# DJ Profiles the member is part of
has_and_belongs_to_many :disc_jockeys,
:join_table => ''members_are_disc_jockeys'',
:uniq => true
end
class DiscJockey < ActiveRecord::Base
# Members that are part of this DJ profile
2006 Jan 31
2
How can I overwrite the parent.children.push(child) Method?
Hi all
I want to overwrite the push method (which is an alias of <<, the same
as concat) of collections, and there I want to test if :uniq is set to
true in the relationship. If so, the method should check if the passed
object is already related to the parent, or not (only then it will be
added).
But I just can''t find the original code of this method, so I could
overwrite
2009 Jan 25
1
habtm relation and dependent => :destroy
Hi all ,
I have a habtm relation between 2 tables:
- users
- rights
If there a way to affect a destroy dependance on those 2 tables only for
the last instance? In my opinion, dependent => :destroy is not the
solution because this delete all the linked instance.
For example, if I have:
# in User model this:
- "Joooooo"
- "Jeannnn"
- "Tommmm"
# in Right
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 Mar 04
0
HABTM Relation / Save Question
Ok, so I have two models that HABTM each other.
Companies
UserAccounts
When creating a new user account, this works:
@company.user_accounts << @user
This works with or without a subsequent save of @company.
And the association is set properly but this does nothing (fails silently):
@user.companies << @company
This fails both when I do and don''t save @user afterwards.
2006 Jan 12
0
HABTM with conditional field in relation table
Hi all
I have members in my application, and every member can assign other
members as buddies.
class Member < ActiveRecord::Base
# Hat folgende Buddies
has_and_belongs_to_many :buddies,
:class_name => ''Member'',
:join_table => ''members_have_buddies'',
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
2006 Mar 21
2
Need :through to work as has many rather than HABTM.
I''ve a horrible feeling I''m missing something here, but I''d like to have
something like :through to model a has_many relationship rather than a
HABTM relationship (and I don''t think it does).
The is the model I have (simplified):
Users have many Models (and Models belong to Users)
Models have many Pieces (and Pieces belong to Models)
In (badly drawn)
2006 May 30
3
extra attributes in habtm
Hi,
Posting here since issue tracking isn''t the best place to discuss.
I can understand habtm is moving towards deprecating support for extra
attributes in join_table, and to use :through for those cases instead.
To clarify, patch<http://dev.rubyonrails.org/attachment/ticket/5216/habtm_join_table_test.patch1.diff>for
#5216 <http://dev.rubyonrails.org/ticket/5216>
2006 May 24
2
"Stack Level Too Deep" issue in HABTM Unit / Functional Test
Hello guys. I was able to figure out that my "stack level too deep"
error I was getting with my HABTM destroy method was the result of a bug
in rails 1.0. I upgraded to 1.1.2 and now the views and any console-run
commands for destroying AR objects linked together via HABTM work just
fine.
I have HABTM setup between stories and submissions.
The issue is that the destroy methods in
2006 Feb 16
1
HABTM -VS- belongs_to/has_many, for self-referential joins
Ok, David says on page 241 that sometimes a many-to-many relation with
attributes are better implemented as an actual model instead of using HABTM.
Well, I''ve got that situation and I can''t figure it out.
All of the examples in the book have HABTM examples between 2 different
tables, but I want to have a HABTM relation on 1 table with itself. (e.g.,
if I have a table Things,
2006 Jan 04
2
Updating Attributes in a HABTM Join Table
Is there a way to update attributes in a HABTM join table? Right now
I am deleting the join and then recreating it with new attributes.
I have a table "categories" and another table "items". They are both
HABTM with the join table "categories_items" between them. If an item
is joined to a category once, no problem, we create the join. But if
an item is
2006 Jun 05
7
Is HABTM Dying?
For a while, I''ve been getting that HMT is replacing HABTM. It appears that
HMT can do all of what HABTM can do and more. The question is: Should I stop
using HABTM? Let''s take a simple case:
A case has many categories
For a given category, there are certain valid statuses
Category
has_and_belongs_to_many :statuses
Status
has_and_belongs_to_many :categories
Question:
Is
2006 Feb 14
1
Another HABTM Question
Hi there,
I have a question on what would be the best way to save a HABTM model.
A posting habtm categories, and a category habtm postings.
class Category < ActiveRecord::Base
has_and_belongs_to_many :postings
end
class Posting < ActiveRecord::Base
has_and_belongs_to_many :categories
end
In my blog_controller, where the actual posting is saved, is where I
think I''m
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 Nov 04
0
Model.delete_all vs Model.destroy_all in a habtm
Hi there
I have an habtm association between 2 Models.
I regularly have to truncate the table on one side of the relationship
and repopulate the table with a fresh csv file.
I notice that f I do Model.delete_all, none of the records in my habtm
join table get deleted, whereas if I use destroy_all they do.
However, the overhead of using destroy_all is too great. For the
amount of records I have
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 Feb 07
1
habtm :uniq causing duplicate inserts? How to update Rails?
Hello *Gem* experts,
Sorry for asking multiple questions in one post but they are both related to one problem.
So far I have the following code:
class Member < ActiveRecord::Base
has_and_belongs_to_many :blogs, :uniq=>true
.....
end
class Blog < ActiveRecord::Base
has_and_belongs_to_many :members, :uniq=>true
...
end
The issue is that
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