I have a class instance variable on one of my AR classes. I set its value at boot with an initializer and, after that, never touch it again except to read from it. In development mode, this value disappears after the first request to the web server. However, when running tests, using the console or running the production server this d...
I have a model Foo with attributes id, name, location.
I have an instance of Foo:
f1 = Foo.new
f1.name = "Bar"
f1.location = "Foo York"
f1.save
I would like to copy f1 and from that copy, create another instance of the Foo model, but I don't want f1.id to carry over to f2.id (I don't want to explicitly assign that, I want the db to ha...
Is there a way to combine scopes in an additive fashion?
If I have the scopes
User.big_haired
and
User.plays_guitar
I can call
User.big_haired.plays_guitar
and get all the users who have big hair AND play guitar. Can I write this to get all users who have big hair OR play guitar?
I guess I have to add that I realize that you ...
I'm trying to get a list of active record results to display as a plist for being consumed by the iphone. I'm using the plist gem v 3.0.
My model is called Post. And I want Post.all (or any array or Posts) to display correctly as a Plist.
I have it working fine for one Post instance:
[http://pastie.org/580902][1]
that is correct, wh...
Using ruby, camping webframework, activerecord-2.1.1, my db structure is ...
create_table :Conf_posts do |t|
%w{title body username posttime hit passwd}.each do |col|
t.column :"#{col}", :string
end
end
I want sum of each username's hit
I have the following code.
Post.find :all, :select => "username,sum(hit)", :from => "Co...
I have a recursive relationship between models:
Test
--> Questions
-------> (has_one) Remediation
------------> (has_many) Remediation_Questions
-----------------> (has_one) Question
Basically the idea is each question has a remediation (some link or block of text) associated with it. Each Remediation then has a set of remediation que...
I need to have a view able to update an array attribute on a model such that I can dynamically add things on the view to be able to add this. Does that even make sense?
Basically a Foo has urls. So in the DB I just have a text datatype that I want to store the comma separated list of urls, and I override the default AR setter and getter...
I have an Account model and a User model:
class Account < ActiveRecord::Base
has_many :users
end
class User < ActiveRecord::Base
belongs_to :account
end
Users belong to an account and an account have a user maximum (different for each account). But how do I validate that this maximum have not been reached when adding new users to ...
Hi there,
While working on the login part of an application, I find myself running into an issue:
My model is based on Active Record, by extending Zend_Db_Table_Row objects. Whenever I have to deal with a user, I'd want to do this through the User object (being an extended table row). However, Zend_Auth_Adapter_DbTable::getResultRowO...
Hi all
I am wanting to create an application that can allow users to add products for sale.
I want to make it so that a user can add whatever type of product he/she likes and let them also create stored and searchable attributes for their products - alot like google base does.
Does anyone know of the best way to do this ie model it.
...
Say I'm writing a blog app with models for posts, pages and photos. I've got a category model, that may be linked to any of these models. So, a category may contain various kinds of items. Every item only has ONE category.
I could implement this using a generic tagging pattern with a join table, but I want to make sure every subject can...
How can I sort an array returned by an activerecord query by a 'created_at' date column? Keep in mind, this is once the query has been executed. Don't tell me to do it in the query because I need this to happen in the view.
Thanks
...
It seems to me that it is possible to break ruby on rails such that neither scaffolding works anymore nor database migration when particular model names are used.
In particular I noticed this when using "Dispatcher" for a model to be created via scaffold. If I created the same object with a different name everything works fine.
Has any...
I am struggling pulling a simple list of records from one table object and printing them out.
I have a table called [Acceptance] that has four fields, two of which allow nulls. Here is the ddl for the schema object:
CREATE TABLE [dbo].[Acceptance](
[AcceptanceID] [int] IDENTITY(1,1) NOT NULL,
[AcceptanceCode] [nvarchar](2) NOT...
I am continuing to delve into Erlang. I am thinking of starting my next web project using Erlang, and at this stage the only thing I will really miss from Ruby on Rails is ActiveRecord.
Is there a good alternative technology for Erlang?
Update:
The closest I have come to a solution is to ErlyDB, a component of ErlyWeb.
ErlyDB is a...
I have something like this:
$this->db->set('val', 'val+1', FALSE);
$this->db->where('id', $id);
$query = $this->db->update(TABLE_NAME);
How can I then go and get the new value of 'val'? Do I have to do another select or can I get it off of $query?
...
This is not exactly a question, it's rather a report on how I solved an issue with write_attribute when the attribute is an object, on Rails' Active Record. I hope this can be useful to others facing the same problem.
Let me explain with an example. Suppose you have two classes, Book and Author:
class Book < ActiveRecord::Base
belong...
I have a SQL query that isn't table-specific and I don't know how to handle it with Ruby On Rails.
Here my SQL query (you don't need to understand it):
SELECT type, actor_id, events.created_at, photo_id, photos.user_id FROM
(SELECT 'comment' AS type, user_id AS actor_id, created_at, photo_id FROM comments
UNION
SELECT 'classification'...
Is there any way to tell active record not to log the ansi color codes when its logging stuff?
Eg. I do not want this in my logs.
[4;36;1mSQL (0.1ms)[0m [0;1mSELECT count(*) AS count_all FROM `users` WHERE (`user`.id = 133) [0m
Instead I want this:
SQL (0.1ms) SELECT count(*) AS count_all FROM `users` WHERE (`user`.id = 133)
I...
as an example, i have a model Group and model User
they are connected with :has_many, :through => groups_users
groups_users table has an attribute, called moderator, specifying whether a user is a moderator of the group
question: how do i access all moderators of a given group?
after reading about :with_scope, what comes to mind is
...