search for: department_id

Displaying 20 results from an estimated 28 matches for "department_id".

Did you mean: department_a
2006 Nov 08
4
writing SQL query WHERE.. IN.. anArray ?
...n array @dpt_ids ex : @dpt_ids = ["43", "48", "49", "50", "51"] I try to insert it into my sql query to be used in a ''find_by_sql'' query = "SELECT * , #{kms} AS km FROM cities" query << " WHERE department_id IN ( #{dpt_ids} ) " but this transform my array into a unique string : '' 4348495051'' I also tried query << " WHERE department_id IN ( #{dpt_ids.each {|d| p d }} ) " same.. How could I get the following resulting query : WHERE department_id IN ( "4...
2006 Mar 01
2
Validating that a foreign key is present and ok
...lidate that a model object''s attribute is a valid foreign key? The problem is, I can''t check if the attribute is a valid foreign key if the attribute doesn''t even exist. For example, every employee must be in a department. In the following code, if an employee''s department_id is not present then Department.find_by_id(department_id) might cause problems, yes? class Employee < ActiveRecord::Base validates_presence_of :department_id def validate errors.add(:department_id) unless Department.find_by_id(department_id) end end department_id should be present, a...
2006 Mar 13
3
validates_associated problem
Hello, I have a situation where an ''employee'' belongs to a ''department'' and have setup the relationship as follows. class Employee < ActiveRecord::Base belongs_to :department, :foregin_key => "department_id" validates_associated :department_id end class Department < ActiveRecord::Base has_many :employees def validate_on_update unless self.find_by_id(id) error.add(:id, "is invalid department") end end However when I try to save an employee with some test department ...
2006 Mar 22
0
Another Problem with params
I am trying to do a similar thing for some spares that I am trying to manage... My spare.rb file is as under class Spare < ActiveRecord::Base belongs_to :department, :class_name => ''department'', :foreign_key => ''department_id'' belongs_to :subequipment, class_name => ''subequipment'', :foreign_key => ''sub_equipment'' <snip> My view reads <snip> <p><label for="spare_department">Department</label><br/> <select name="s...
2006 Apr 06
6
pagination question
i''ve figured out how to use the next and previous links with the paginator class but now i''m trying to figure out how to display all the page numbers in between. looking through the rails api, i found paginator.each() but i''m not sure how to use it, or if that''s even what i am looking for. also, is there a way to limit the amount of pages like some sites
2006 Feb 23
4
MySQL Duplicate Key Error
...NULL auto_increment, `name` varchar(20) NOT NULL default '''', `description` varchar(100) NOT NULL default '''', `section_id` int(10) unsigned NOT NULL default ''0'', `designation_id` int(10) unsigned NOT NULL default ''0'', `department_id` int(10) unsigned NOT NULL default ''0'', `view` varchar(1) NOT NULL default ''1'', `create` varchar(1) NOT NULL default ''0'', `modify` varchar(1) NOT NULL default ''0'', `delete` varchar(1) NOT NULL default ''0'...
2005 Dec 21
3
How to make a drop-down automatically submit an AJAX form
...he submit button, all is fine, but i''d like to know how to make it automatic. My RHTML code looks a bit like this: -- <%= form_remote_tag :update => "div_id_dataentry_bottom_ajax", :url => { :action => "dataentry_bottom_edit" } %> <select id="department_id" name="department_id" onchange="this.form.submit();"> <%= options_from_collection_for_select @departments, "id", "department_name" %> </select> <%= submit_tag "Open for Data Entry" %> <%= end_form_tag %> <div...
2012 May 07
1
Complex sorting question, or not?
I have a function that displays all depts and related info from other tables in my Department model, such as: def dept_and_hospital "#{name} (#{floor.building.hospital.name})" end ... which is used in my view, like: <p> <%= f.label :department_id %><br /> <%= collection_select(:device, :department_id, Department.all(), :id, :dept_and_hospital, :prompt => ''Select Department'') %> </p> How do I sort the display names by the hospital name (which is a few "tables away" in the db schema),...
2006 Mar 30
3
Model.find(:all) where Model.association has more then 0 items?
Hi everyone, I have a Department model that has_many people. How do I go about finding all departments with more than 0 people? Department.find(:all, :conditions => Department.people.size > 0) That, of course, doesn''t work, but it was as close as I could come. Thanks! Sean
2006 Mar 13
7
Problem with params
I''ve got a User model, which holds the following (excerpt): def try_to_authenticate User.authenticate(self.username, self.password) end .. private def self.hash_password(password) Digest::SHA1.hexdigest(password) end def self.authenticate(username, password) @user = User.find(:all, :conditions => ["username = ? AND password = ?",
2006 Mar 12
3
Newbie: using find like a sql join query
I have a working Rails app with several related tables, but can''t find an answer to this question in the Dave Thomas Rails book. Imagine for example: table departments with columns: id, department_name table employees with columns: id, department_id, employee_name and of course the employees table has a constraint foreign key (department_id) references departments(id) So this is really basic stuff, I have this working fine in my app. I have in the model: departments has_many :employees, and employee belongs_to :department What I want to...
2006 Apr 26
2
two layers of has_many
...ployees of a company? class Company < ActiveRecord::Base has_many :departments def employees Employee.find_by_sql("SELECT employees.* FROM companies, departments, employees WHERE companies.id=departments.company_id AND departments.id = employees.department_id" ORDER_BY employees.last_name) end end class Department < ActiveRecord::Base belongs_to :company has_many :employees end class Employee < ActiveRecord::Base belongs_to :department end I am using Rails 1.0 if that matters. Does it matter? Does the new has_many :th...
2010 Aug 02
7
Complex associations
...:Base; end class Store < ActiveRecord::Base; end class Department < ActiveRecord::Base; end class Product < ActiveRecord::Base; end A StoreType has many stores and a Store has many Department. However, both Store and Department have many products. An product has the columns store_id and department_id which are mutually exclusive. This is because a Product may belong directly to a Department, or it may be a ''global'' product that belongs directly to the Store. What I''d like to do is have an association in the StoreType model that would give me all products for that St...
2005 Dec 23
0
Problem with large join table and ActiveRecord
...having a hard time explaining this, so I hope i can say this correctly. I have these tables: people id fname lname departments id name buildings id name room wtkeys id key_number key_way Issued_keys id people_id department_id building_id wtkey_id date_issued My question is when i need to insert a new issued_key do I just do something like: person = Person.new person.fname = "Robert" person.lname = "Boone" person.save! dept = Department.new dept.name = &q...
2006 Aug 03
0
autocomplete and one to many relationships
Hello, I am trying to get autocomplete to save record ID. I have to tables: Students and Departments. Students table has department_id field. Department table has 2 fields: id and name I set up belongs_to: and  has_many: entries in the models of each. In my _form.rhtml I have the autocomplete line that is working: &lt;%= text_field_with_auto_complete :department, :name %&gt; ie. If I start typing, I get a pull-down li...
2006 Aug 04
0
Fwd: autocomplete and one to many relationships
Hello, I am trying to get autocomplete to save record ID. I have to tables: Students and Departments. Students table has department_id field. Department table has 2 fields: id and name I set up belongs_to: and  has_many: entries in the models of each. In my _form.rhtml I have the autocomplete line that is working: &lt;%= text_field_with_auto_complete :department, :name %&gt; ie. If I start typing, I get a pull-down li...
2007 Jul 09
3
NoMethodError when using find_by_sql
I''m try to verify users on login. Here is my code: def self.authenticate(username,password,account_code) employee = self.find(:all, :select => "e.id, e.first_name, e.last_name, e.username, e.account_id, e.department_id, o.pay_type_id, o.admin_yn, o.payroll_yn, o.files_yn, o.dept_report_yn,e.salt, e.hashed_password", :conditions => ["e.deleted_yn=0 and e.username = ? and a.account_code = ?", username, account_code], :joins => "as e left outer join options o on e.id = o.employe...
2007 Dec 03
5
spec for model_id should eql
...sole, I''m just having difficulty getting this spec to work. Any pointers would be appreciated. Failure message: ''Address fetch and geocode should extract department and write to address object'' FAILED expected 3, got nil (using .eql?) This spec that is failing: @address.department_id.should eql(3) before: before do @address = Address.new @address.attributes = valid_address_attributes @address.save @department = mock_model(Department) @department.stub!(:find_by_code).with("75").and_return("3") end The line of code I am writing the s...
2006 Jan 18
22
Creating multiple child objects from the same form
I''ve been digging into rails, but this one question has been a two day stumper. I''ve got a question/answer model that I''m trying to work out. Each question has multiple answers (they''re more like choices, it doesn''t matter whether they''re right or wrong), and I''d like to have the question creation form also have multiple fields in
2006 Jan 31
6
Pagination - why is it this hard?
...#39;last_name ASC'', :per_page => 20 end def search searchconditions = [] if params.include?(:letter) searchconditions = ["LOWER(last_name) LIKE ?", params[:letter].to_str + "%"] elsif params.include?(:department) searchconditions = ["department_id = ?", params[:department]] elsif session[:q] if params[:q] session[:q] = params[:q].downcase searchconditions = [ "LOWER(username) LIKE ? OR LOWER(first_name) LIKE ? OR LOWER(last_name) LIKE ? OR LOWER(preferred_name) LIKE ?", "%&...