List Info

Thread: fixture magic with associations: never use a FK id again!




fixture magic with associations: never use a FK id again!
user name
2006-10-17 11:19:48
I've written some fun code to ease the pain of associating
between
fixtures.  'Tis tested and documented!  Essentially it
allows you to
replace this syntax

  user_id: 5

with this:

  user: :joe

as long as you have users.yml with

joe:
  id: 5


http://blog.caboo.se/articles/2006/10
/17/named-references-for-test-fixtures
http://dev.rub
yonrails.org/ticket/6424

There's not much actual code in there, and I sacrificed
brevity for readability.
Comments?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-coregooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-core
-~----------~----~----~----~------~----~------~--~---

fixture magic with associations: never use a FK id again!
user name
2006-10-17 14:38:09
How do the dependencies work? Does it just scan the
already-loaded
fixtures? Use the first-found in case of duplicate keys?

On 10/17/06, Courtenay <court3naygmail.com> wrote:
>
> I've written some fun code to ease the pain of
associating between
> fixtures.  'Tis tested and documented!  Essentially it
allows you to
> replace this syntax
>
>   user_id: 5
>
> with this:
>
>   user: :joe
>
> as long as you have users.yml with
>
> joe:
>   id: 5
>
>
> http://blog.caboo.se/articles/2006/10
/17/named-references-for-test-fixtures
> http://dev.rub
yonrails.org/ticket/6424
>
> There's not much actual code in there, and I sacrificed
brevity for readability.
> Comments?
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-coregooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-core
-~----------~----~----~----~------~----~------~--~---

fixture magic with associations: never use a FK id again!
user name
2006-10-17 18:17:08
No.  Once all fixtures are loaded from this statement

fixtures :foo, :bar

It looks in :foo and :bar as the table names to match.  It
will only
attempt to match if the value in this statement is a symbol:
  user: :fred

In the case of duplicate keys, you're on your own and
probably have
bigger fish to fry.
If you're relying on symbols loading into fixtures you're
probably
screwed, but then, who does that?

This is intended to be a really lightweight addition for
people on the
golden path of rails.  More advanced matching algorithms of
course
welcome.


On 10/17/06, Obie Fernandez <obiefernandezgmail.com> wrote:
>
> How do the dependencies work? Does it just scan the
already-loaded
> fixtures? Use the first-found in case of duplicate
keys?
>
> On 10/17/06, Courtenay <court3naygmail.com> wrote:
> >
> > I've written some fun code to ease the pain of
associating between
> > fixtures.  'Tis tested and documented! 
Essentially it allows you to
> > replace this syntax
> >
> >   user_id: 5
> >
> > with this:
> >
> >   user: :joe
> >
> > as long as you have users.yml with
> >
> > joe:
> >   id: 5
> >
> >
> > http://blog.caboo.se/articles/2006/10
/17/named-references-for-test-fixtures
> > http://dev.rub
yonrails.org/ticket/6424
> >
> > There's not much actual code in there, and I
sacrificed brevity for readability.
> > Comments?
> >
> > >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-coregooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-core
-~----------~----~----~----~------~----~------~--~---

fixture magic with associations: never use a FK id again!
user name
2006-10-27 23:11:15
Been waiting for this for a while.  Thanks for the patch!

Remind me why yaml is preferred to a ruby DSL again?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-coregooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-core
-~----------~----~----~----~------~----~------~--~---

fixture magic with associations: never use a FK id again!
user name
2006-10-27 23:11:15
Been waiting for this for a while.  Thanks for the patch!

Remind me why yaml is preferred to a ruby DSL again?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-coregooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-core
-~----------~----~----~----~------~----~------~--~---

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )