I have these tables and relationships:
user has_many projects
project has_many tasks
task has_many actions
I would like to build a scope that allows me to select all of the current users actions, regardless of what project or task they belong to.
Thanks
...
I'm using the acts-as-taggable-on gem and I need to use find_related_tags on my survey model to get back 3 surveys every time. In the event there aren't always 3 related I need to pick how ever many are related plus some random ones to get to 3. Additionally I have a method I wrote called completed_survey_ids which return an array of s...
I have a a Comments table and a Posts table, where a Post has many comments and a comment belongs to a post (i.e. it has a post_id in the table).
How can I efficiently select the last ten Posts that DO NOT have comments.
I can't seem to accomplish this without first selecting all the posts and checking each for a 0 comment count.
Thank...
Hi -
I want to configure my app to use a different schema than the default for storing sessions. Basically, I want the app to store all its active_record objects in app_development and only its sessions in app_sessions. Normally this could be done by defining the sessions db in database.yml:
development:
# ...
sessions:
host:...
Hi everybody,
I've though a bit about the activerecord vs. manual queries in Codeigniter. ActiveRecord is awesome when it's all about standard queries and holds development time really low.
However, when there's a need to add some complexity to the queries, the ActiveRecord gets quite complicated to work with. Sub queries or complex j...
I am running a query with Active Record in a modal of my codeigniter application, the query looks like this,
public function selectAllJobs()
{
$this->db->select('*')
->from('job_listing')
->join('job_listing_has_employer_details', 'job_listing_has_employer_details.employer_details_id = job_listing.id', 'le...
I have a class Foo which has_many Bars. Foo has an attribute, some_id. I want to Retrieve all Bar instances where the Foo has some_id = N. In SQL this translates into something like:
select * from bar inner join foo on foo.id = bar.foo_id WHERE foo.some_id = N
...
I am trying out Castle ActiveRecord. I want to use the Validation features AND the LINQ features.
In order to use LINQ, you can either:
My preference: Make your entities inherit from ActiveRecordLinqBase<T>, then to query:
var blogs = (from b in Blog.Queryable select b).ToList();
Use ActiveRecordLinq.AsQueryable<T>, e.g.:
var blogs ...
I have a table named ChatSessions where I keep track of active users in the chatroom. I need to prune expired user sessions from the table every 10 minutes. Using pure php-mysql is plain simple but I'm totally clueless how to convert this into ActiveRecord in CodeIgniter. The plain SQL query is below:
SELECT *
FROM `ChatSessions`
WHERE ...
I have the following Subsonic 3.0 query, which contains a nested NotIn query:
public List<Order> GetRandomOrdersForNoReason(int shopId, int typeId)
{
// build query
var q = new SubSonic.Query.Select().Top("1")
.From("Order")
.Where("ShopId")
.IsEqualTo(shopId)
.And(OrderTable.CustomerId).NotIn...
I am using ActiveRecord in Rails 3 to pull data from two different tables in two different databases. These databases can not join on each other, but I have the need to do a simple join after-the-fact. I would like to preserve the relation so that I can chain it down the line.
here is a simplified version of what I am doing
browsers ...
how can I write a NOT IN in named scope syntax? For example, User :has_many Photos, how can I define:
User.has_no_photo
and returns all users who are not in the Photo model? thanks!
...
We have a single server/single database application that uses NHibernate and Castle ActiveRecord, SQL Server sits behind it.
As part of the processing I need to write as many as 1.2 million rows of data. Using ActiveRecord and NHibernate is woefully slow and needs to be improved - this could easily be done with an "insert into .. select...
Is it possible to use ActiveRecord named_scopes to create one query with sql OR clauses?
When I use
Model.scope1.scope2
generated query is conjunction of these scopes.
...
I'm running a query and then decrypting it in the controller. After it is decrypted I was putting the results into an array and sending that to the view. The problem is with this solution I need to rewrite all of my views to parse the arrays sent instead of the active record objects sent before.
Is there a way to turn the decrypted arr...
class Addressee < AR::Base
end
class Employee < Addressee
belongs_to :person
belongs_to :company
end
class Person < Addressee
has_many :employees
has_many :companies, :through => :employees
end
class Company < Addressee
has_many :employees
has_many :people, :through => :employees
end
Given the models above, when I ru...
I've got an application running on Rails 2.3.5, on a Linux box, and I need to connect to Sql Server 2005 for one of my models.
I've been reading up on this, and it's getting frustrating, can't find a solution that works thus far. I've done this before using JRuby and JDBC, but I can't use Java in this scenario.
Any pointers to a failsa...
I have 2 simple named scopes defined as such:
class Numbers < ActiveRecord::Base
named_scope :even, :conditions => {:title => ['2','4','6']}
named_scope :odd, :conditions => {:title => ['1','3','5']}
end
if I call Numbers.even I get back 2,4,6 which is correct
if I call Numbers.odd I get back 1,3,5 which is correct
When I chain t...
How do you generate an input's id attribute, given a model? For example, if I have a model of Person with a first_name attribute, the form helper prints out a textbox with this html:
<input type="text" id="person_first_name" />
How can I generate that person_first_name from some other place in the code (like in a controller or some pl...
I am using a lot of my own validation methods to compare the data from one association to the other. I've noticed that I'm constantly checking that my associations aren't nil before trying to call anything on them, but I am also validating their presence, and so I feel that my nil checks are redundant. Here's an example:
class House <...