ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> rubyonrails-talk
rubyonrails-talk
[Rails] Completely un-understandable behavior in a simple Model
by K. Rajesh other posts by this author
Aug 13 2007 4:54AM messages near this date
[Rails] Re: html_escape method | [Rails] HEALTHY LIFESTYLE !!! ооо
Hi,

I have been working on RoR for about 8 months now. I have 3 websites
live and running well on RoR using all sorts of inter-table
relationships (has_many, HABTM, has_many, :through -= you name it).

It is in this background that the results I am seeing today are taking
me completely out of my depths.

I have 2 tables
1) tasks
2) opportunities
and Task and Opportunity corresponding to them as models.

So, I go to
ruby script/console
and say
t = Task.find(:all)
and then I do
t[0].class
and it says Opportunity!!!!!!
How is this possible? Of course, I did this exercise in script/console
because none of the relationships that I had mapped into Task were
getting detected.

For more detailed info, here are the models

class Task < ActiveRecord::Base

	set_table_name "tasks"
	validates_presence_of :who_id, :what, :due_date
	belongs_to :opportunity, :foreign_key =>  "ref_id"
	belongs_to :who, :foreign_key =>  "who_id", :class_name => "User"
	belongs_to :creator, :foreign_key =>  "created_by", :class_name =>
"User"

	def self.filter_by_responsibility(id)
		find(:all, :conditions =>  "who_id = #{id} and status =
'Open'", :order =>  "type, due_date")
	end

	def self.filter_by_opportunity(opportunity_id)
	      find(:all, :conditions =>  "ref_id = #{opportunity_id} and type
= 'Opportunity' and status = 'Open'", :order =>  "due_date asc")
	end
end


class Opportunity < ActiveRecord::Base
	belongs_to :contact
	belongs_to :business_line
	belongs_to :line_owner, :class_name =>  "User", :foreign_key =>
"line_owner_id"
	belongs_to :cxo_owner, :class_name =>  "User", :foreign_key =>
"cxo_owner_id"
	has_many :tasks
	has_many :pending_tasks, :class_name=> "Task", :conditions=>"status !=
'Done'"
	belongs_to :proposal_owner, :class_name =>  "User", :foreign_key =>
"proposal_owner_id"
	belongs_to :proposal_currency, :foreign_key => 
"proposal_currency_id", :class_name =>  "Currency"
	validates_numericality_of :proposal_value, :message =>  ": Enter
proposal value without commas, decimal points etc", :if =>  Proc.new { |
o| !o.proposal_value.blank? }

	def self.overdue_closures
		find(:all, :conditions =>  "expected_closure_date <= '#{Date.today}'
and current_status != 'PO'", :order =>  "line_owner_id")
	end

end

WHAT IS HAPPENING HERE? WHAT AM I MISSING? IT CANT BE RAILS. IT NEVER
IS.

Regards,
Rajesh


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Ta
lk" group.
To post to this group, send email to rubyonrails-talk@[...].com
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@[...].com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved