I'm trying to implement the Active Record pattern to a ZF project.
I used to work with a similar approch before and it works well.
But my problem now, is about how to handle many-to-many relationship with my models.
Here is an example :
Let's say i've an User model.
<?php
require_once 'MLO/Model/Model.php';
class Model_User extends...
This is my first time using Rails and I was wondering if it's possible to load a has one polymorphic association in one SQL query? The models and associations between them are basic enough: An Asset model/table can refer to a content (either an Image, Text, or Audio) through a polymorphic association, i.e.
class Asset < ActiveRecord::...
Hi,
i'm working on multisite and I'd like to share session data between two or more sites. I have session id, but what is the best way to retrieve session data from cookie store? Or it will be better to enable ActiveRecord session store and use find_by_session_id method to retrieve session data? Using this way - I need to configure one s...
As the result of yesterday's discussion , I have decided to use Castle ActiveRecord for my ORM task. I have added attributes to the class according to the starting guide. After fixing some obvious errors, I was greeted with this:
*Could not find configuration for CLASS_XXX or its root type Castle.ActiveRecord.ActiveRecordBase this is us...
I am familiar with SubSonic 2.2 and am coming up to speed with 3.0 and am unsure of the best way to do something. I have a CSV file that I am parsing and then inserting the records into the database. I want to be able to process the batch of inserts all at once. IE I would like to parse through the records and add them to a List inser...
I am trying to implement before_destroy on a model. While I am following this before_destroy example I either receive a NameError or end up with something which doesn't do the before_destroy. What's wrong with my syntax?
class Person < ActiveRecord::Base
has_many :book_loans, :order => 'return_date desc'
has_many :books, :through =...
The uniqueness validator of ActiveRecord has an options to skip validation if the value is nil or blank. Even if I set both parameters to true (the default behaviour) I can create one record with nil and blank before the validation hits. I use the default SQlite3 Database sqlite3-ruby (1.2.5).
Edit for clarification: I get the expected ...
I a little confused about how this work even if it works properly. I have a model that has two association to the same other model.
Company has an owner and company has many employees of the class users.
here is my company model:
class Company < ActiveRecord::Base
validates_presence_of :name
has_many :employee, :class_name => '...
When doing a search in active record I'm looking for record's that do not have an archived bit set to true.
Some of the archived bits are null (which are not archived) others have archived set to false.
Obviously,
Project.all(:conditions => {:archived => false})
misses the projects with the archived bits with null v...
Hi,
I'm building a social networking website. I have a table of Users. Each user can have a number of other users as friends, so I have a second table Friends:
user_id
friend_id
Based on this answer I'm trying to create the relationships. I have,
class User < ActiveRecord::Base
has_many :friends, :dependent => :destroy
has_many :...
I'm a total Ruby/Rails/AR noob. I have a very basic sort of database schema that I can't seem to figure out the best way to represent in the Rails Way.
Table Post
String title, author
Text content
Timestamp posted
Post parent
The idea here is that top level posts will have parent that is NULL. Every response will hav...
When I add the following block of code in environments.rb, ActiveRecord::Base extends the module in the development environment but not in the test environment.
require "active_record_patch"
ActiveRecord::Base.send(:extend, ModelExtensions)
The library file which contains the module is as follows:
module ModelExtensions
def human_...
As I move through the iterations on my application*(s) I accumulate migrations. As of just now there are 48 such files, spanning about 24 months' activity.
I'm considering taking my current schema.rb and making that the baseline.
I'm also considering deleting (subject to source control, of course) the existing migrations and creating a...
Hi,
is there a way to get the original value that an ActiveRecord attribute (=the value that was loaded from the database)?
I want something like this in an observer
before_save object
do_something_with object.original_name
end
The task is to remove the object from a hash table (in fact, move it to another key in the table) upon u...
I have a couple of scripts that interact with a MySQL database using ActiveRecord without the rest of the Rails package (although I have the complete Rails gem installed). However, trying to use these classes lately has been giving me the NoMethodError when I try to call find() on my ActiveRecord-descended class.
The class code is amazi...
In my current project, we got a rather unusual request(to me). The client wants all the deletion procedure to mark a flag instead of physically delete the record from the database table. It looks pretty easy at the first glance. I just have change
public void DeleteRecord(Record record)
{
record.DeleteAndFlush();
}
public IList G...
I have this situation:
Stories has many Tasks
Tasks have an integer called hours_left
I need a named scope to find Stories which all its tasks has more than 0 hours left.
Based on this post. I wrote this:
class Story
has_many :tasks
named_scope :uncompleted, {
:joins=>["INNER JOIN tasks ON tasks.story_id = stories.id"],
...
Is it possible to limit an AR :include to say only pull in one record...
Item.find(:all,
:include => [ :external_ratings, :photos => LIMIT 1 ])
I have a list of items and each item has between 5 and 15 photos. I want to load a photo id into memory, but i don't need all of them, I just want to preview the first one.
Is there a ...
Good day all,
We are doing a data migration from one system to a Rails application. Some of the tables we are working with are very large and moving them over 1 record at a time using ActiveRecord takes far too long. Therefore we resorted to copying the table over in SQL and validating after the fact.
The one-by-one validation check ...
Hi
I'm creating a C# application using ActiveRecord as my datalayer. I've created a business class named UserGrabber which is supposed to find users by using it's properties to send as filters into a ActiveRecord.Find Method.
For example a User class. The client needs to find all users that have active directory name starting with "ann...