Posts

Showing posts with the label Activerecord

Codeigniter Active Record Left Join

Answer : You have wrong where clause you need to compare user_id from your table ,you are comparing the id of email to the provided $user_id $CI->db->select('email'); $CI->db->from('emails'); $CI->db->where('user_id', $userid); $CI->db->join('user_email', 'user_email.user_id = emails.id', 'left'); $query = $CI->db->get(); A more useful way is to give aliases to your tables so the tables with same columns will not have any confusion $CI->db->select('e.email'); $CI->db->from('emails e'); $CI->db->join('user_email ue', 'ue.user_id = e.id', 'left'); $CI->db->where('ue.user_id', $userid); $query = $CI->db->get();

Can You Get DB Username, Pw, Database Name In Rails?

Answer : From within rails you can create a configuration object and obtain the necessary information from it: config = Rails.configuration.database_configuration host = config[Rails.env]["host"] database = config[Rails.env]["database"] username = config[Rails.env]["username"] password = config[Rails.env]["password"] See the documentation for Rails::Configuration for details. This just uses YAML::load to load the configuration from the database configuration file ( database.yml ) which you can use yourself to get the information from outside the rails environment: require 'YAML' info = YAML::load(IO.read("database.yml")) print info["production"]["host"] print info["production"]["database"] ... Bryan's answer in the comment above deserves a little more exposure: >> Rails.configuration.database_configuration[Rails.env] => {"encoding"=>"unico...