Forum: Ruby on Rails Wrong id after join!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
74592905ef38cd087e5b73c0955aaa18?d=identicon&s=25 Martin Smith (Guest)
on 2006-02-28 22:40
The Problem
-----------

After using a join in my find the id attributes set in my Entity objects
are wrong!  It is setting the Entity id to the value from Postcode id!

The Code
--------

entities = Entity.find(:all,
  	            :conditions => [...omited...],
  	            :joins => "as e inner join postcodes as pc on
substring_index(e.postcode,' ', 1) = pc.outer_part " )

Produces the folowing SQL
-------------------------

SELECT * FROM entities as e inner join postcodes as pc on
substring_index(e.postcode,' ', 1) = pc.outer_part WHERE (categories_id
= 4 and pc.metres_x >= 367400.0 and pc.metres_x <= 399400.0 and
pc.metres_y >= 380600.0 and pc.metres_y <= 412600.0)
5321dd2dc03ca82c1fed417cb1c94b95?d=identicon&s=25 Steven Beales (Guest)
on 2006-02-28 22:50
(Received via mailing list)
This has happened to me a few times .... just add a :select to be safe

 entities = Entity.find(:all,
              :conditions => [...omited...],
              :joins => "as e inner join postcodes as pc on
 substring_index(e.postcode,' ', 1) = pc.outer_part ",
:select=>'e.*' )


Steven Beales
Chief Software Engineer
Medical Decision Logic
724 Dulaney Valley Road
Towson
Maryland
21204
410-828-8948



"Martin Smith" <linus141275@hotmail.com> wrote
in message news:9b7be90ab588d84b1f063b098e353b39@ruby-forum.com...
This topic is locked and can not be replied to.