Displaying 20 results from an estimated 2000 matches similar to: "habtm relation and dependent => :destroy"
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 Jan 18
1
HABTM - Destroy just the relationship
If I have a HABTM relationship between two models (places, pictures),
can I delete the record from the join table without also destroying the
objects?
IE:
1. @places.pictures << @picture
2. @places.pictures.find( @picture.id ).destroy
I''d want line #2 (...or something similar unless I''m way off) to destroy
the record in pictures_places only, and not anything from the
2006 May 18
1
HABTM destroy works in console, not in web browser.
In console I can set image = Image.find(id) and then do image.destroy
and it works fine. It even cleans up the HABTM relationships thanks to a
before_destroy method. The problem is though that when I try and do the
same thing in my web browser, either in my view or via the URL scheme of
/controller/destroy/id it gives me a "stack level too deep" error.
Anybody know why it would work
2006 Mar 13
6
:dependent => :destroy
Hi,
There is something I don''t understand about :dependent => :destroy. I
hope someone can help me. Consider this code:
class Folder < ActiveRecord::Base
has_many :myfiles
has_many :folders
has_many :group_folders, :dependent => :destroy
validates_uniqueness_of :name, :scope => "folder_id"
validates_presence_of :name
before_destroy
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 Jan 31
2
Habtm: I can create the same relation more than 1x!
Hi all
I have a DiscJockey and a Member model, each of them reference each
other using habtm.
josh $ script/server
>> m=Member.find 1
>> dj=DiscJockey.find 1
>> m.disc_jockeys << dj
>> m.disc_jockeys << dj
>> m.disc_jockeys << dj
Now I have 3 relations in the DB! Is this normal? Shouldn''t there an
error occur, that I can only add the
2005 Dec 20
0
Problem destroying in unit tests with HABTM
Hi converted two of my models to HABTM today but I am having a real
hard time getting my unit tests to pass now. Specifically, when I
destroy a record I get this error:
...many many lines of this above...
(eval):4:in `destroy_without_habtm_shim_for_categories''
(eval):4:in `destroy_without_habtm_shim_for_categories''
(eval):4:in
2006 Nov 08
0
Prevent an object from being destroyed in HABTM relationship
Hello all,
I have the following models:
class Sku < ActiveRecord::Base
has_and_belongs_to_many :options
end
class Option < ActiveRecord::Base
has_and_belongs_to_many :skus
end
By default if I destroy an Option any relationships between Options and
Skus will be removed as well.
But, I want to prevent an Option from being destroyed when it is
associated with a Sku in the options_skus
2006 Oct 25
4
need help on special HABTM relation
hey all,
I have three tables like this:
forum (id,title)
usergroup(id,title)
forum_perms(usergroup_id,forum_id,read,write,post)
is there a way to deal with that kind of relation with rails such as by
using has_and_belongs_to_many kind of stuff?
thanx in advance
Pat
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
2008 Oct 21
6
detecting width overflow in serialized column with mysql
So I''ve got an ActiveRecord model pointing to a MySQL db, with an
auto-serialized column ("serialize :columnName").
Thing is, MySQL, depending on how it''s configured (like, by default),
has a bad habit of just truncating your data if it''s too wide for the
column, with no error raised. Yeah, I can probably reconfigure MySQL
and/or my AR connection to it. But
2008 Dec 13
3
how to do "special queries" ala The Rails Way on "associated" conditions?
I have the following in a model class:
class Game < ActiveRecord::Base
has_many :player_stats
has_many :players, :through => :player_stats
def visitor_stats
stats = []
player_stats.each do |stat|
stats << stat if stat.player.team.team_code ==
self.visiting_team_code
end
stats
end
def home_stats
stats = []
player_stats.each do |stat|
stats << stat if
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
2008 Dec 20
4
uninitialized constant BooksController::Books
hi new to rails ...
wat does it means...
uninitialized constant BooksController::Books
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:102:in
`const_missing''
app/controllers/books_controller.rb:5:in `index''
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are
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
2009 Feb 19
3
Associated child records not created on creation of a parent.
I am trying to create a record with association. Within the create
method, I would also like to pre-populate dependent (has_many) records
from a template in the database.
The child records are <u>mysteriously rolled back </u> if I insert
them in a loop. If I try to insert a single child record, it works.I
have read the books and tried to google my way out of this but am at a
dead
2006 Mar 12
0
NameError when trying to combine Recipe 14 (rich HABTM) & Rec. 10 (self-ref HABTM):
Hi all,
I''m trying to model self-referential relations between people, where the
relation has attached data.
John ''works for'' Bob
Problem: '':through'' doesn''t work, and generates a NameError.
=> the models :
Person (attr: name)
Relation (attr: source_id, target_id)
(more details below)
ex: John ''works
2008 Nov 12
5
dynamic condition for has_one and eager loading issue
Hi,
I ve defined the following relation in one of my models with a dynamic
where condition:
has_one :selection,
:foreign_key => ''object_id'',
:conditions => ''selection_type = 1 and account_id = #
{self.send(:account_id)}''
That works perfect, however when I try to eager load that relation I
am getting the following error when doing a
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>
2008 Dec 13
3
session In the model
Hi
i have the model SDTicket which has a field modified_by_id and it has
to take data from session[:id] Now this SDTicket model has many
associated models like Activity one of them So when ever an activity
happens then also the value in session[:id] is to be go to
modified_by_id field
SDTicket has_many activities
Activity belongs to SDTicket
So for that what I am trying is in Activity