Okay, here's one for the pro's:
For a couple of years now, i've been working on my own PHP ORM/ActiveRecord implementation that i named Pork.dbObject.
It's loosly based on the 'make your own site with rails in 5 minutes' movie we all saw a couple of years ago. You can do things like:
$clients = dbObject::Search("Client", array("ID > 5...
Given the following two (simplified) models:
class Customer < ActiveRecord::Base
# finder sql to include global users in the association
has_many :users, :dependent => :destroy,
:finder_sql => 'SELECT `u`.* FROM `users` `u`
WHERE (`u`.`customer_id` = "#{id}" OR `u`.`customer_id` IS NULL)'
validates_presence_of :name
end
clas...
I'm trying to write an ActiveRecord find query with no success. Please help!
This feature of my project is kind of a blog with Digg-like features: each registered user can add a star to the blog post itself or any of its replies.
So here are the relevant model classes:
BlogPost (has_many Replies)
Reply (belongs_to Blog Post)
Starrin...
ActiveRecord query caching is enabled when a controller's action is invoked. I also know that you can do something like this to temporarily enable caching for a given Model for a given code block:
User.cache do
....
end
But is there a way to enable query caching for other contexts (e.g. when a script is run under the rails envi...
How would you model the references and citations to publications (articles, books, chapters, etc...)?
A publication can be an article, book or a chapter and it has many references to other publications and other publications refer to it (call these citations)
I need to be able to list the relationships among the publications: The refer...
Hello,
I'm trying to put a rails face on a legacy database. It is an old Sybase
11 database installation. I've gotten an ODBC connection working that
uses unixODBC and FreeTDS to work. I'm also using the
activerecord-odbc-adapter gem.
I've had to use set_table_name and set_primary_key to make it work so
far. However, none of the dynami...
Is it necessary to unit test ActiveRecord validations or they are well-tested already and hence reliable enough?
...
I'd like to have a ActiveRecord implementation in Java and before crafting my own, I'd like to know if there is an open source implementation of it.
I am aware of other successful java OR maping tools like Hibernate, Castor, etc... and that is not what i want, i want a ActiveRecord like in RoR:
RoR ActiveRecord
.NET Castle ActiveRecor...
I need to do something like this
class User < ActiveRecord::Base
has_many :abuse_reports
end
class AbuseReport < ActiveRecord::Base
belongs_to :abuser, :class_name => 'User', :foreign_key => 'abuser_id'
belongs_to :game
end
class Game < ActiveRecord::Base
has_many :abuse_reports
end
@top_abusers = User.page(params[:page],
...
I like Active Record but many say it's bad in performance compared to Hibernate. There should be some good article out there but google can't help me.
...
Afternoon,
Lets say I have gather a random selection of users:
User.find(:all, :limit => 10, :order => "rand()")
Now from these results, I want to see if the user with the ID of 3 was included in the results, what would be the best way of finding this out?
I thought about Array.include? but that seems to be a dead end for me.
Thanks...
Let's say I've got the following ActiveRecord class:
[ActiveRecord]
public class Account
{
...
[BelongsTo("CustomerId")]
public Customer Customer { get; set; }
}
Currently, to set the value of the CustomerId field I have to get the entire Customer object from the database and assign it to the Account:
Customer customer =...
I'm building a simple blog with comments. There is a Post model and a Comment model. Every interaction between the two works fine except for creating new comments. I'm having an issue in Rails when trying to post a new comment:
wrong number of arguments (1 for 0)
Here are the request parameters (from the stack trace):
{"commit"=>"Pos...
I am wondering how to 'seed' an auto incrementing primary key value using Castle AR? For Example wanting the Orders table primary keys to start out as 10000. Is this something that is 1. possible 2. a good solution for creating order numbers?
Maybe there is a way to have consecutive auto incrementing field on the DB that is NOT the pk...
My application has the concept of a "Loan". Each loan has a creditor, a debtor, and an amount.
From a database perspective, I know that I want the loans table to look something like this:
|id|Amount|creditor_id|debtor_id|
| 1| 100| 5| 7|
Where creditor/debtor ids reference User ids (i.e., the primary key for rows in...
I am providing a web service to be called by external companies. The required data covers several models including person, address etc. I want to validate the received data conditionally based upon some fields within the request. I will eventually have many differing sets of validation data, although currently I only have one and I am ab...
I'm having a very strange problem. I'm getting a collection of Rails ActiveRecord models back from the database but the first model in the collection does not have the model attributes/methods, just the standard ActiveRecord base methods. The rest have all the attributes. And it's only doing this on my production debian server using Pas...
Hello,
I have a class that derives from ActiveRecord::Base.
This class has a subclass that is differentiated in the database by a type id column.
How do I make sure that all the inherited active record functions in the derived classes append the type_id column to the conditions hash on any queries that are executed by the derived class?...
When I serialize a hash containing UTF8 strings, like this:
poll.variants = {0 => 'тест',1 => '-тест-',2 => 'test # test "тест'}
to an ActiveRecord field, the resulting field contains:
---
0: !binary |
0YLQtdGB0YI=
1: !binary |
LdGC0LXRgdGCLQ==
2: !binary |
dGVzdCAjIHRlc3QgItGC0LXRgdGC
The utf8 strings get treated as bi...
Hi, I'm developing a ruby on rails app and I want to be able to excecute a method on every AR object before each save.
I thought I'd create a layer-super-type like this:
MyObject << DomainObject << ActiveRecord::Base
and put in DomainObject a callback (before_save) with my special method (which basically strips all tags like "H1" fro...