Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

new table name set by set_table_name not used by model

#4992

test case example:

class PostDraft < Post
  set_table_name 'post_drafts'
end

assert_difference("PostDraft.count") do
  Post.set_table_name 'posts'
  Post.create

  Post.set_table_name 'post_drafts'
  Post.create
end

Test will fail because the second Post.create will still insert into posts table instead of post_drafts table, but if you check Post.table_name you'll get 'post_drafts'. The correct behavior should be:

either A. insert into post_drafts table on the 2nd Post.create
or B. raise an error on the 2nd Post.set_table_name to keep consistence (if this is not a bug but a feature, lol)

(attached a patch for A)

Reported by Jan Xie · June 28th, 2010 @ 09:11 AM

State: committed
Milestone: none
Assigned to: Aaron Patterson Aaron Patterson
Importance: Low

Activity

  1. Jan Xie
    Jan Xie
    • Tag changed from rails 3.0.0.beta4, table_name to activerecord set_table_name test, rails 3.0.0.beta4, table_name

    June 28th, 2010 @ 09:16 AM

  2. Jan Xie
    Jan Xie
    • Tag changed from activerecord set_table_name test, rails 3.0.0.beta4, table_name to rails 3.0.0.beta4, table_name

    June 28th, 2010 @ 09:16 AM

  3. Jan Xie
    Jan Xie

    table_name_prefix= and table_name_suffix= have the same problem too.

    June 28th, 2010 @ 10:38 AM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Tag changed from rails 3.0.0.beta4, table_name to rails 300beta4, table_name

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 05:01 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:01 PM

  6. Jan Xie
    Jan Xie
    • State changed from stale to open
    • Tag changed from rails 300beta4, table_name to table_name

    Still exists in latest rails. I update the patch in attachment, including a test case.

    [state:open]

    February 3rd, 2011 @ 12:51 PM

  7. Jan Xie
  8. Aaron Patterson
    Aaron Patterson
    • State changed from open to incomplete
    • Importance changed from to Low

    AR tests fail when I apply this patch:

      1) Failure:
    test_raises_error(InvalidTableNameFixturesTest) [test/cases/fixtures_test.rb:447]:
    FixtureClassNotFound expected but nothing was raised.
    

    February 3rd, 2011 @ 07:04 PM

  9. Jan Xie
    Jan Xie
    • Assigned user set to Aaron Patterson

    The problem is class FunnyJoke added by patch is suppoesed to not exist, so FixtureClassNotFound will be raised.

    I renamed FunnyJoke to GoodJoke, now all passed. See below updated patch.

    February 4th, 2011 @ 02:13 PM

  10. Jan Xie
    Jan Xie
    • No changes were found…

    February 5th, 2011 @ 12:52 PM

  11. Jan Xie
    Jan Xie
    • State changed from incomplete to open

    [state:open]

    February 5th, 2011 @ 12:53 PM

  12. Aaron Patterson
    Aaron Patterson
    • State changed from open to committed

    Applied and pushed, thanks!

    February 8th, 2011 @ 06:33 PM