Displaying 20 results from an estimated 10000 matches similar to: ":has_many and :after_save"
2010 Aug 18
11
When after_save isn't after the save....
I have a Production model, which represents a farmer''s crop. After
create (via after_save) I call a method that creates one or more
Supply models, which represent a week of anticipated product harvest.
After each of those are created, a class method gets called that tries
to match each new Supply with outstanding orders for the same time
period. If a match is made, a transaction (an
2010 Apr 15
12
[PATCH] Add :touch option to has_many associations
Hi,
it would be nice to have the touch option in has_many associations also.
I have a scenario like this:
An user has some credit (money) and some advertises. Each advertise can be
enabled or disabled depending on some rules. One of the rules is that the
user should have money. Each time the money of the user change, the
advertises are touched, enabled/disabled and then cached, as they are much
2009 Feb 21
3
belongs_to or has_many
2 tables Items and Categories
Categories (id, name)
Items (id, name, category_id)
Category_id can be null, and there are Categories that has not an Item.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email
2009 Mar 29
2
after_create and after_save
Hi,
AFAIK after_create is called after_save if the entry does not exist in
the DB.
Is there a way to tell if a specific model is new or not in
after_save?
I have to do something like:
def after_save
add_to_history ''save''
end
def after_create
add_to_history ''create''
end
However after_save is called when creating too.
--
cheers,
M.
2010 Mar 13
6
Find first or create
Is there any ActiveRecord''s dynamic finder that can allow me to find
first association or create it if it doesn''t exist. Something like this
(not this code is conceptual - it does not work!):
Comment.posts.find_or_create(:first)
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2006 Jul 17
2
Very strange after_save problem. Please help.
I have a very strange problem here. I do not get this. So any help is
greatly appreciated.
Basically I have a model that calls a method in the background
process in the "after_save" method. Let''s call the model products. So
what happens is this:
1. I create a new product.
2. Everything works and the product is saved with id 13.
3. A method is called in my background
2006 Jul 17
2
after_save deletes is an exception is raised?
Does after_save in a model delete if an exception is raised in there?
I simply did
def after_save
raise ''hmmm''
end
and it raised the exception but there was nothing in the database. I
removed that entire method and its in the database. Is this correct?
Thank You,
Ben Johnson
E: bjohnson@contuitive.com
-------------- next part --------------
An HTML attachment was
2006 Jul 17
5
Keeping attributes of two models in sync
Hi,
I have a Product and a corresponding Keyword (1:1 via belongs_to and
has_one). I want to ensure, that two attributes (:name) of the two
models alway stay in sync. What''s the easiest way to accomplish that?
I did play around with before_/after_save hooks and with
AR::Observers but in the end I''d always get infinite recursion...
Thanks,
Timo
2008 Jul 28
1
callback executed like after_save but after transaction
I''m trying to add some code for my ActiveRecord class so that it is
executed whenever an object is updated, this code is a seperate
process that reads from the same table represented by my model class
so when it runs it needs the database to be up to date.
In the following situation this is fine:
# MyModel
def after_save
`/usr/local/bin/update_models -i #{self.id}`
end
# controller
2010 May 12
2
How to add an after_save callback on runtime on a particular instance
class User < AR
end
user = User.new
Let''s say that I have a user instance with me. After this record is
saved I want an after_save callback which would print the id of the
record.
The only catch is that I am not allowed to change the User class. How
can I accomplish my goal? Is that even possible to add an after_save
callback on a particular instance object. Any metaprogramming
2009 Apr 28
1
chmod in rails development
What chmod value I am supposed to use for rails app development? Is 777
a good idea? Or should I use sudo when I run my commands (such as
script/server)?
--
Posted via http://www.ruby-forum.com/.
2009 Jan 18
2
after_save -- stack level too deep
Hi all,
I''m running into a brick wall trying to figure out my problem here. I
have a model that has a boolean property called "paid". I''d like to
add the following to my model:
def after_save
self.amount == self.splits.sum(:amount) ? self.update_attribute
(:paid, true) : self.update_attribute(:paid, false)
end
The problem is, when I do this I get an error that
2009 Sep 22
6
Import excel / csv files
Hey,
What way is the best to do imports of CSV files?
2006 Feb 17
3
Using :include with has_one vs. has_many
While I''m happy to continue talking about the vagaries of Rails deployments, I
also need to actually build apps. :)
I may have discovered a bit of a problem with :include as it applies to has_one
associations. First, let me say that I''m a big fan of :include for reducing the
number of SQL calls. There are times when I wish it could go more than 1 step
away from the parent
2008 Apr 18
3
has_many and belongs_to with non-primary foreign keys
Hi,
I''m having a bit of trouble with my first Rails app.
----
I have two tables:
create_table :items do |t|
t.column :created_at, :timestamp
t.column :user_id, :int
t.column :text, :text
end
create_table :users do |t|
t.column :user_id, :int
t.column :name, :string
end
----
I''m trying to use the "user_id" field to link both tables, with each
user
2006 Mar 15
4
help with DRY violation
I''m trying to be a good rails developer and fix DRY violations as i find
them. However, i''m trying to fix this one, i cant seem to get it to work.
I have two tables A and B that have a one-to-one relationship. Table B
belongs_to Table A. Table A has_one Table B. I''m creating instances of
Table A in different places, depending on the controller. However, for each
2012 Jul 10
1
has_many association with autosave issues
I''d like to use autosave => true for an association for its added benefits:
the parent doesn''t save unless the children saves. However, it seems to
skip validations when saving the children. And this seems to be the case
since the beginning of time...
Anyone know why?
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2010 Oct 04
2
newbie q on activerecord - has_one and has_many on same table?
Hi I have a table where I need to identify one of the children as the
"prime" child.
So, its like:
Parent
has_many :Child
has_one: Child :as :prime_child (?)
or something like that? Do I put something like prime_child_id in the
Parent table?
Thanks.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this
2010 Dec 14
5
Build associated model confusion
I''m new to Rails3, and I''m just trying to get one last thing to work
before I call it a night. The situation is the following (please if
the code is horrible, just let me know, still learning):
I want to log a dive. I might have a new location on that dive at
which point I have to create a new Location, and then create the dive.
A dive has_one location. A location has_many
2008 Nov 13
3
Creating a file and saving in public directory
Hello,
I''m fairly new to Ruby on Rails.
I have a model called Report and I''m trying to create a text file that
is saved in a /public/report directory.
I''ve had a look at the ruby api but I can''t seem to get this working.
The current code I have is:
#report.rb
class Report < ActiveRecord::Base
after_save :write_file
def write_file
if @file_data