Aliases
A factory can register one or more aliases — alternative names that look
up the same definition. Aliases also drive the implicit-association lookup
(see Associations), so a :post factory whose :author
column references a :user factory is one alias away from working without
an explicit declaration.
Declaring aliases
Pass an :aliases named argument when defining a factory. It accepts either
a single string or a list:
1 2 3 4 5 6 7 8 9 | |
factory-by-name returns the same FactoryDefinition for the canonical name
and every alias, so any downstream code that looks up the factory sees the
same record.
Collision detection
Aliases share a namespace with factory names. Any collision raises
X::ORM::Factory::DuplicateAlias immediately:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
Reload
ORM::Factory.reload clears the alias map along with the registry. Looking
up an alias after a reload raises X::ORM::Factory::UnknownFactory.