Benefits
1. Allow for choice of naming conventions
Example a relationship between Members and Contacts where each member can
have multiple contacts. Currently the relations are retrieved:
$member->Contacts
$contacts->Members
if you use camelCase coding standards then you need to add a foreignalias
and localAlias to each relationship to acheive this:
$member->contacts
$contacts->members
if it were two words it would be $member->oneTwo
REQUIREMENTS:
1. Should only transform the alias if one is not provided through the
comment block
IMPLEMENTATION
add function:
-- converts first character of given string to lowercase
function lcfirst(s)
-- only lowercase the very first char, leave all others untouched
return string.lower(string.sub(s, 0, 1)) .. string.sub(s, 2, #s)
end
change:
relName = underscoresToCamelCase(foreignClass)
to
relName = lcfirst(underscoresToCamelCase(foreignClass))
change:
if ( foreignAlias == nil or foreignAlias == "" ) then
if ( foreignKey.many == 1 ) then
if ( config.preventTableRenaming ) then
-- foreignAlias = config.preventTableRenamingPrefix ..
pluralizeTableName(foreignClass)
foreignAlias = config.preventTableRenamingPrefix ..
pluralizeTableName(localClass)
else
-- foreignAlias = pluralizeTableName(foreignClass)
foreignAlias = pluralizeTableName(localClass)
end
elseif ( foreignKey.many == 0 ) then
-- foreignAlias = foreignClass
foreignAlias = localClass
else
foreignAlias = "FK " .. foreignKey.name .. " is broken! It
has no destination cardinality (many is not 0 and not 1)."
end
end
to (only updates the ones not using table prefix and that are generated
from localClass)
if ( foreignAlias == nil or foreignAlias == "" ) then
if ( foreignKey.many == 1 ) then
if ( config.preventTableRenaming ) then
-- foreignAlias = config.preventTableRenamingPrefix ..
pluralizeTableName(foreignClass)
foreignAlias = config.preventTableRenamingPrefix ..
pluralizeTableName(localClass)
else
-- foreignAlias = pluralizeTableName(foreignClass)
foreignAlias = lcfirst(pluralizeTableName(localClass))
end
elseif ( foreignKey.many == 0 ) then
-- foreignAlias = foreignClass
foreignAlias = lcfirst(localClass)
else
foreignAlias = "FK " .. foreignKey.name .. " is broken! It
has no destination cardinality (many is not 0 and not 1)."
end
end
Original issue reported on code.google.com by Jason.Br...@gmail.com on 21 May 2010 at 9:22
Original issue reported on code.google.com by
Jason.Br...@gmail.com
on 21 May 2010 at 9:22