Displaying 20 results from an estimated 10000 matches similar to: "Expression Interpolation and ActiveRecord relationships"
2006 Jun 30
0
Interpolation in association conditions broken; broken backwards-compatibility?
I believe it used to be possible to interpolate values into
associations'' conditions with single quotes, but it isn''t anymore.
has_many :widgets, :conditions => ''brand_id = #{brand_id}''
Anyone else remember that? It seems to have been snuffed out in
changeset 3897 with the removal of interpolate_sql(@conditions)
Was the change (and the fact that it
2005 Dec 12
2
How to use arbitrary relationships in Activerecord
How can I ask ActiveRecord to make it''s "has_many" code to work on some
arbitrary relationship between two tables? ie neither field is a primary key
The situation is that I am writing a Postfix management application and
one of the tables to manage is the "alias" table. My primary key in the
"mailbox" table is "id", but the alias table is just
2005 Dec 27
0
How do I combine :finder_sql and :conditions to perform a sub-search on a custom has_many relationship?
I''m sure there''s something right under my nose that I''m missing.
I have two tables with two parallel one-to-many relationships. I wish
to use the :finder_sql parameter to essentially ''or'' the two foreign
keys.
What isn''t working for me is performing a ''sub-search''.
Let''s say the tables are "stores" and
2006 Jan 12
2
ActiveRecord models w/ base condition
Does anyone know how to do the following? I have 3 different AR classes
that all map to the same table. The only difference between this AR classes
is that they should only return record that match a certain condition.
For example, Foo should only return records from table ''list'' that follow
the condition ftype="foo", where as Bar, on the other hand, should only
2006 Jul 01
0
activerecord generating wrong syntax with postgresql
I''m using activerecord outside of rails and find_first generates sql
that postgresql doesnt'' like. This is rails 1.1.4, with everything up
to date via "gem update".
This is the command line:
ruby -rrubygems seca -c ../etc/seca.cnf cert --export 1 --format
pkcs12 --key root.key >root.pfx
This is the error:
(PGError: ERROR: argument of WHERE must be type
2008 Nov 12
5
dynamic condition for has_one and eager loading issue
Hi,
I ve defined the following relation in one of my models with a dynamic
where condition:
has_one :selection,
:foreign_key => ''object_id'',
:conditions => ''selection_type = 1 and account_id = #
{self.send(:account_id)}''
That works perfect, however when I try to eager load that relation I
am getting the following error when doing a
2005 Dec 27
3
Trouble combining :has_many, :finder_sql and :conditions to create a sub-search
I''m sure there''s something right under my nose that I''m missing. I
have two tables with two parallel one-to-many relationships. I wish to
use the :finder_sql parameter to essentially ''or'' the two foreign
keys.
What isn''t working for me is performing a ''sub-search''.
Let''s say the tables are "stores" and
2006 Feb 13
4
Table Relationships and ActiveRecord Associations
First of all, I love Ruby on Rails. I have an intermediate
understanding of PHP, JavaScript, DOM and CSS, and that''s the extent of
my programming experience. I''m developing an online game''s web presence
with another colleague. We''re the only two technical guys on a team of
+10 content developers. So, baring all that in mind, here are my
questions with a
2007 May 30
2
newb trying to figure out ActiveRecord relationships
3 tables. item, brand, commercial
item
--------
id
name
brand_id
name
brand
---------
id
name
commercial
----------
id
item_id
The idea is that a commercial will have one item.
each item will have brand.
and a brand may have zero to many items.
I can''t figure out how to make the relationships for my models.
Eventually, i''d like to be able to show a brand name from a
2006 Feb 13
0
has_many finder_sql #{id} single/double quotes voodoo
I never would have figured this out in many moons:
has_many :subscribers, :class_name => "Person",
:finder_sql =>
''SELECT DISTINCT people.* '' +
''FROM people p, post_subscriptions ps '' +
''WHERE ps.post_id = #{id} AND ps.person_id =
p.id '' +
''ORDER BY p.first_name''
Variable
2006 Nov 04
0
one to many relationship; has_one
I''m new to ruby and rails and as a result am a bit lost on implementing
a one to many relationship. In my DB I have 2 tables contents and
locations, contents contains the foreign key location_id. I generated a
content and a location model using rails scripts and then edited the
models as follows
class Content < ActiveRecord::Base
has_one :location
end
class Location <
2006 Mar 21
3
Newbie - ActiveRecord relationships
So I''ve worked through Agile Web Development with Rails and I''m now
trying my first little app to get into the swing of things. Its a task
tracking app where people can create tasks and assign them to others,
and also log time against the tasks.
I''m having trouble working out the model relationships. This is what
I''ve got so far, but its not right as
2006 Jan 17
15
legacy database and finder_sql nightmare!
This is my first rails app with a legacy database and I''m having a
terrible time getting the models set up correctly. I have an order
table that has a primary field named order_number. I have a name table
with a primary of item_number. These two tables are liked by the
item_number and the order_number, but not as you might think. If the
order_number is 2500, then each entry in
2006 Aug 15
2
has_many + finder_sql & :include
Hello,
In a model I have:
has_many :things, :finder_sql => '' select * from other_things '' +
'' where id = #{id} ''
When I do MyClass.find(:all, :include => :things) I get a weird error:
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in
2006 Feb 28
3
[AR] #{id} namespace visibility used in finder_sql
Dears,
[Rails 1.0.0]
I''m working with a legacy schema, and around my 20+ models i''ve used
some AR constructs.
They are based on a finder_sql doing some dirty sql and using #{id}
from the ''pivot'' model for extracting data in other tables.
like :
class Division < ActiveRecord::Base
set_table_name "legacy_division"
set_primary_key
2006 Oct 30
2
It this possible: finder_sql-like behavior for belongs_to?
Guys,
I have a need to support as has_many/belongs_to relationship on a
legacy(kind of) schema. The reason I say kind of is that the schema does
have "id" columns that are used in many associations, but this particular
has_many/belongs_to association needs to support different ones.
I''ve attached to code at the end of this email. Suffice it to say I need to
use the standard
2006 Jan 19
7
bug in has_many count?
I can submit a patch, but wanted to confirm I''m looking at this right...
The docs indicate that if you specify a has_many association with
:finder_sql, but no :counter_sql, it constructs the appropriate counter
sql by substituting the SELECT clause.
But has_many_association.rb doesn''t seem to do that -- it just passes
Base#count_by_sql the finder_sql, which doesn''t
2006 Mar 14
4
has_one
I''ve got an order model that stores order data.
One piece of data is a credit card type, which is a digit 1,2 or 3.
I have a cardType model that has an id, shortName and LongName for the
credit card merchant (visa, mastercard, amex).
I want to be able to say: order.cardType.shortName, but can''t seem to
get has_one working. It works with has_many and a finder_sql statement
on
2010 Jan 25
0
has_many, :finder_sql, setting attributes
Hi all,
My question is somewhat complicated, but bear with me. My project has a
number of models: User, Program, and Team. Users belong to multiple
Programs. Programs have multiple teams, but Teams belong to one
program. For each Program a User belongs to, he can belong to multiple
Teams. (Think of this in an athletic context where users are athletes,
programs are universities). So my
2006 Jun 03
8
confused about ActiveRecord relationships
I am very confused about where to put the belongs_to and the has_one
(and other relationship identifiers). I have read the RDoc and the
agile book many times about this and I think i still see it backwards.
Let me outline my app so you have an understanding...
I have 2 tables:
Schools { id, school_name, address_id }
and
Addresses { street1, street2, city, state, zip, country }
*** this