I thought it was possible to create a new model object through an association?
class Order < ActiveRecord::Base
belongs_to :basket
end
class Basket < ActiveRecord::Base
has_one :order
end
order = Order.new()
basket = order.basket.new() # NoMethodError: undefined method `new' for nil:NilClass
...
I have a Ruby on Rails application that has two active environments, Stage and Production. Our development team has been using Stage, but we would like to move our data onto the production server for various reasons. However, there are conflicting ID's in the new database, so it's not as simple as pulling the data from one location and...
Hello,
I'm writing an application on top of CodeIgniter to better organize my ebook collection. I'm nearly done, but I realize my 'browse' page is running far too many queries - two per book - to get their information. Obviously not at all ideal, especially since I have about 1000 books to put into this system.
I currently have one mo...
I've got a series of Posts and would like to select all posts where its title size is lesser than 30, how to do that?
Posts.where("len(title) < 30")?
...
I am trying to setup a has_many :through relationship between two models
User and CustomerAccount through another join model AccountOwnership
(users and account_ownerships tables are in one db, say db1 and the customer_accounts table is in remote db, say db2).
Here is the relevant code, that sets up the associations
class User < Activ...
I noticed that Rails doesn't trigger after_initialize callback when the callback symbol is passed as input.
The code below doesn't work.
class User < ActiveRecord::Base
after_initialize :init_data
def init_data
puts "In init_data"
end
end
The code below works.
class User < ActiveRecord::Base
def after_initialize
...
Hey,
How would i use code igniters active records to insert/update/select data from a database using mysql's built in aes encrypt/decrypt functions?
I know i could just use the normal sql query, but i'd like to use active records ideally.
Thanks
...
Hi all,
It's a long time I'm working with NHibernate session through frameworks like Castle ActiveRecord but never understood what is a session exactly and how should manipulate. Can anybody help? Is there any concise resource?
Thanks in Advance
...
I am trying to have a pack of very generic named scopes for ActiveRecord models like this one:
module Scopes
def self.included(base)
base.class_eval do
named_scope :not_older_than, lambda {|interval|
{:conditions => ["#{table_name}.created_at >= ?", interval.ago]
}
end
end
end
ActiveRecord::Base.send(:inc...
Trying to get to total number of users for a given event and I'm thinking what I've got should work, but I get the following:
Could not find the source association(s) :squads_users in model Squad. Try 'has_many :users, :through => :squads, :source => '. Is it one of :team, :event, :event_division, :users, :point_adjustments, :checkpoi...
I am trying to use update_all through an association, and i am getting mysql errors, anyone know why please?
class Basket < ActiveRecord::Base
has_many :basket_items
has_many :articles, :through => :basket_items
def activate_articles
articles.update_all :active => true
end
end
class BasketItem < ActiveRecord::Base
belong...
(Sorry for long post) Ok guys, so I'm having some issues with something I'm trying, I've been trying to fix it for a long time now, and It's now time to ask for help.
Ok, so I have these "grinders", and I want a user to vote for each one,
I did two scaffolds:
grinder grinder:string posted_timestamp:datetime poster_ip:string votes_up...
Hi,
I've just come across the Star Schema for Report-Aggregation. The first Question that came to my mind is whether or not Doctrine ORM supports such denormalized Tables. As I've seen ist, there are a feww kinky behaiviours in dealing with relations, a Model could not completely know.
Any ideas? Is it possible?
...
I have a page with a list of devices. Every device has a detail page. What i'm trying to achieve is get a list of all projects belonging to a device on the device detail page. A device can have several projects, and a project can also be linked to several devices (many-to-many relation). I have a table in my database to link the device a...
So in rails I use sqlite3 for development and mysql for production. Sqlite3 and mysql handle booleans differently ("t" or "f" in sqlite3 and true or false on mysql). Usually it's not a problem when I do a find because I can do this:
Comment.find(:all, :conditions => ["viewed = ?", false])
And rails will insert the appropriate value de...
Here's some of my production code (I had to force line breaks):
task = Task.find_or_create_by_username_and_timestamp_and_des \
cription_and_driver_spec_and_driver_spec_origin(username,tim \
estamp,description,driver_spec,driver_spec_origin)
Yes, I'm trying to find or create a unique ActiveRecord::Base object. But in current form it's...
Event
has_many :squads, :dependent => :destroy
has_many :users, :through => :squads, :source => :squad_users
Squad
has_many :squad_users, :dependent => :destroy
has_many :users, :through => :squad_users
User
has_many :squad_users
has_many :squads, :through => :squad_users
has_many :events, :through => :squads
SquadUser
belongs_...
for
class A < ActiveRecord::Base
has_many :bs
has_many :cs, :through => :bs
end
class B < ActiveRecord::Base
belongs_to :a
belongs_to :c
end
class C < ActiveRecord::Base
has_many :bs
end
If i bring up a rails console, and do
a = A.new
b = a.bs.build
b.c = C.new
Then i get
a.cs => []
but
a.bs[0].c => c
If a is save...
For my Rails app, we developed an half home-brewed email system. We created a model called Email which then gets added to a queue to be sent (using a web service).
To create templates, we've been just mashing strings together in the model, ie:
Email < ActiveRecord::Base
def self.stock_message(recipient)
email = Email.create do...
My server keeps crashing. It is especially bad in localized parts of my app where the rest is fine. On one major page it is now happening every time. I've spent over an hour cutting out parts of code, restarting the server and seeing where it fails (i.e. whenever any segment of content is inserted), but my code doesn't seem to be reasona...