Displaying 20 results from an estimated 6000 matches similar to: "Wish List: has_many :dependent => {}"
2011 Dec 07
2
Question About Separation Of Concerns (ActiveRecord)
Hello,
I''m a bit stuck with where to put some method calls (separation of
responsibility) and although I''m trying to do it just simply now in the
models, I think my problem raises a bigger question about Fat Models. But
that''s another subject for another day.
Right now, I have ....
Event
has_many meetings
## has an a invitation_expiry date field.
def
2010 Jul 11
10
dependent support for has_many through?
Given the following
class Programmer < ActiveRecord::Base
has_many :assignments
has_many :projects, :through => :assignments
end
if I call Programmer#projects.clear, it will delete_all the joining
assignments; however, I have a situation where I''d like the
assignments to get destroyed instead so that their after_destroy
callbacks get called. It would be simple to
2006 Jun 07
3
#5209 patch: :dependent => :nullify deletes child records
Hi everyone,
A couple of weeks ago I noticed a bug with :dependent => :nullify on
a has_many or has_one. When you delete the parent, the children''s
foreign keys are nullified, as expected. But when you do
parent.child.delete or parent.children.clear, ActiveRecord actually
deletes the child records, rather than just nullifying them.
In my eyes, if you''ve set
2007 Jun 25
1
has_many with :dependent => :nullify
Hi all,
There is something confusing with has_many in the current API :
When deleting a record with association.delete, the corresponding
association''s foreign key is nullified. However, if has_many has
the :dependent option set (to any value), the association''s destroy
method is called instead.
This is awfully inconsistent with the behavior expected when
setting :dependent to
2010 Mar 24
1
How to stub a has_many relationship in Rails 2.3.5
We have a test that has been working find until we upgraded to rails 2.3.5.
I''m not too familiar with mocks/stubs so maybe there is an easy solution.
Here is a simple example of our scenario.
Class Person < ActiveRecord::Base
has_many :aliases, :dependent => :nullify
before_destroy :mark_aliases_as_deleted
def mark_aliases_as_deleted
self.aliases.each do
2007 Dec 30
4
:dependent for not destroying
Hi,
Is there a way to use the :dependent option to set a certain attribute
to null rather than destroying the records?
For example, take the following models:
User
id, integer
name, string
group_id, integer
belongs_to :democrats
Groups
id, integer
name, string
has_many :users
If I delete a certain group, is there a way to have the ''group_id''
attribute of all the
2009 Sep 28
5
Multi-databases support
Hi,
While I was hacking ovirt-server, I have found that it's currently
restricted to Postgres DB. Even if I like postgres for serious work on a
server, I really prefer to hack/dev locally on a Sqlite or MySQL DB.
I have googled on rails in order to find a good answer for the "foreign
key problem" which forces OVirt to stay on pg. I have found a plugin on
this particular
2008 Jul 04
2
How do change catalog before catalog is delted?
In my rails application,there are two models:post and catalog.
One post has a catalog,and one catalog has many posts.
When I delete a catalog,the posts belongs to the catalog will not be
shown normal,for it''s catalog is no existed.
Now I want to create(if the ''Defalut catalog'' is not existed) a
''Defalut catalog'' in catalogs table,and make the
2008 Nov 19
0
has_many through select box in form
Gentlemen,
I have searched the group and have not found any post that clarifies
thsi s=issue to me. Please forgive me in advance if I missed
something.
I have 3 models:
Ticket
has_many :citations, :dependent => :nullify
has_many :violations, :through => :citations
Violation
has_many :citations, :dependent => :nullify
has_many :tickets, :through => :citations
Citation
2007 Jul 17
5
habtm confusion
Hello friends!
I am trying to make a database that will have a group of people set to
committees, and a person can be in multiple committees, and a committee
obviously has multiple people. The people are senators at my
university. These are my current models:
senator.rb:
--
class Senator < ActiveRecord::Base
validates_presence_of :first_name, :last_name, :floor
has_and_belongs_to_many
2006 Apr 25
2
has_many :through
I have:
class Country < ActiveRecord::Base
has_many :states
has_many :cities, :through => :states
has_many :places, :through => :cities
end
What is the query RoR is using when I type:
@places = @country.places
Is it only one query with joins?
--
Posted via http://www.ruby-forum.com/.
2006 Jul 31
0
Issues with has_many, belongs_to and dependency settings
I have 2 models SmsAddress & OutboundSmsAtom
SmsAddress {
has_many :other_objects, :dependency => :nullify
}
OutboundSmsAtom {
#note this object also "belongs_to" other objects if that matters
belongs_to :this_object
}
Whenever I try to destroy an object of type ThisObject, which at the time
has 0 "children" OtherObjects I get the following type of
2006 May 25
0
Has_many, dependent=false, foreign keys legacy issues...
I''m playing around with some legacy schemas; ones that make extensive
use of foreign key update/delete rules. I''ve been working through a
variety of cases to understand how different configurations within Rails
will play with the DB.
If the delete rule is Cascade and :dependent=>false, deleting the parent
deletes the children, exactly as the DB rules specify and do so
2006 Jun 22
1
Active Record question, orphaned children
I have a Deck object and a Card object with their corresponding tables. (You
know a deck of cards.) When I destory a Deck it leaves orphaned cards in
the database. Is there a way to set up the objects with ActiveRecord so that
when a parent object is destoryed the child objects are destroyed as well?
My code below.
class Deck < ActiveRecord::Base
has_many :cards
end
class Card <
2006 Jul 10
0
Dependent nullify doesn''t use save?
If you have a model that has
has_many :clients, :dependent => :nullify
Will that run the save method for each client or will it just simply
nullify the foreign key using straight SQL without every calling
save. Because I have some very important before_save code in my
Client model and I do not think it is getting ran.
Thanks for your help.
Thank You,
Ben Johnson
E:
2010 Jan 06
4
serialized attribute converting to string on reload
Hello,
Anybody help me out? I done googled it good and didn''t find anything
(which should mean that I''ve done something wrong).
Not much code to talk about here, quite simply I have an attribute
that is serialzied and when I update it, irb shows the object and my
methods run on it as it were indeed so. Though when I reload it
changes the data to a string. Not yaml, just one
2006 Apr 15
1
Is this a HAS_ONE bug?
Let''s say I have:
A BELONGS_TO B
B HAS_ONE A (with :dependent=>:nullify)
But this association does not need to exist. In other words, I could
have many A''s and B''s that are not associated in this manner.
Presently, if I try to delete "B":
1. If B is associated to an "A", this works fine and A.my_B is
nullified.
2. If B is NOT associated, I
2003 Dec 23
1
Understanding NT Groups and UNIX Permissions with Samba Shares
Hello, I am having some problems understanding a few concepts in Samba while
trying to use samba-common-3.0.0-14.3E, samba-client-3.0.0-14.3E and
samba-3.0.0-14.3E on RHE 3.0.
Basically, I have security = domain. My system is running winbind, I've
added the winbind calls to nsswitch.conf. I can get my wbinfo -u and wbinfo
-g commands to show me what I want. That all seems happy.
I have a
2010 Sep 16
1
[RFC] function to parse string to argc/argv pair
Currently, I'm looking to improve rosh and would like to start using
getopt(). I'd like to parse a string obtained by fgets() to be like
the argc/argv pair created by __parse_argv but in a way that's more
cross-platform (such that it can also be used by .lnx files rather
than just COM32) and suitable to use in rosh and lua.c32.
I've made a function and inlined a test program for
2006 Jul 19
0
Clearing dependent collections
I have a user model that owns messages :
class User < ActiveRecord::Base
has_many :messages , :dependent => :nullify
end
I''m using nullify so that when the user is deleted, the messages
continue to exist - they''re just marked as being ownerless.
However, calling user.messages.clear actually deletes all his
messages, which I was a little surprised at. I would