ruby on rails - ActiveRecord includes not doing what I expect -


class program   attr_accessible :open, ...   has_many :rounds   has_many :open_rounds, :class_name => 'round', :conditions => ['open = ?', true] end  class round   belongs_to :program   attr_accessible :open, :status, :begin ... end  [64] pry(main)> = program.includes(:rounds)   program load (0.2ms)  select "programs".* "programs"   round load (0.2ms)  select "rounds".* "rounds" "rounds"."program_id" in (4, 6) +----+-------------+-------------+------------+-------+--------+-------------+------------+-------------+ | id | name        | moderato... | descrip... | open  | locked | suppress... | created_at | updated_at  | +----+-------------+-------------+------------+-------+--------+-------------+------------+-------------+ | 4  | advanced... |             | summer ... | false | true   | false       | 2013-04... | 2013-04-... | | 6  | introduc... |             | summer ... | false | true   | false       | 2013-04... | 2013-04-... | +----+-------------+-------------+------------+-------+--------+-------------+------------+-------------+ 2 rows in set [65] pry(main)> 

the sql looks expect, have expected see other columns of round in result of query.

and example 2 same more confusing. notice program 4 has no open rounds:

[67] pry(main)> program.find(6).rounds   program load (0.1ms)  select "programs".* "programs" "programs"."id" = ? limit 1  [["id", 6]]   round load (0.2ms)  select "rounds".* "rounds" "rounds"."program_id" = 6 +----+------------+--------+-------+-----+--------+-------+-----------+----------------+----------------+ | id | program_id | number | start | fin | status | open  | open_date | created_at     | updated_at     | +----+------------+--------+-------+-----+--------+-------+-----------+----------------+----------------+ | 10 | 6          | 0      | 0     | 10  |        | false |           | 2013-04-13 ... | 2013-04-13 ... | | 11 | 6          | 1      | 11    | 21  |        | false |           | 2013-04-13 ... | 2013-04-13 ... | | 12 | 6          | 2      | 22    | 32  |        | false |           | 2013-04-13 ... | 2013-04-13 ... | | 13 | 6          | 3      | 33    | 43  |        | false |           | 2013-04-13 ... | 2013-04-13 ... | +----+------------+--------+-------+-----+--------+-------+-----------+----------------+----------------+ 4 rows in set 

yet when do:

[68] pry(main)> = program.includes(:open_rounds)   program load (0.2ms)  select "programs".* "programs"   round load (0.2ms)  select "rounds".* "rounds" "rounds"."program_id" in (4, 6) , (open = 'f') +----+-------------+-------------+------------+-------+--------+-------------+------------+-------------+ | id | name        | moderato... | descrip... | open  | locked | suppress... | created_at | updated_at  | +----+-------------+-------------+------------+-------+--------+-------------+------------+-------------+ | 4  | advanced... |             | summer ... | false | true   | false       | 2013-04... | 2013-04-... | | 6  | introduc... |             | summer ... | false | true   | false       | 2013-04... | 2013-04-... | +----+-------------+-------------+------------+-------+--------+-------------+------------+-------------+ 

not don't see round attributes, see program 6 didn't expect. again sql looks ok except perhaps "and (open ='f'). because notice there's column called open in both program , round.

sorry dumps wanted lay out evidence clearly. thoughts?


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -