[Solar-talk] Changes afoot: a new Model class
Rodrigo Moraes
rodrigo.moraes at gmail.com
Thu Feb 8 05:19:53 PST 2007
On 2/8/07, Antti Holvikari wrote:
> > I must say i am not a fan of this singular/plural thingie. If I had to
> > do that with french it would be a lot of work which has no added value
> > to me.
> >
> > Keeping everything singular is simpler and removes a layer of magic.
>
> I must say I agree with Arnaud. As of now I vote for singular to keep
> things simple. Then there is no question, what so ever, how to access
> the related records. We like consistency, right? :-) There might even
> be a case where I really don't know the plural of a certain word
> (english isn't my primary language). Also, what if new irregular words
> are added to the dictionary?
Yeah, I think we all would prefer if we could avoid this... I always
code in English, so my concern is more about the extra logic/layer
than with building an equivalent inflector for Portuguese (which would
be very difficult too).
The problem Paul mentioned is how to make the automatic model finding
in _hasOne() / _hasMany() relationships if the names are, let's say,
all singular. Keeping the example of the 'post' model:
$this->_hasOne('blog');
$this->_hasMany('comment');
You would then call $post->comment for the foreign rowset and it would
not be pretty enough; one way to avoid this would be to explicitly
define how the foreign data would be called (the property to access
it) for "to-many" relationships, each time you define _hasMany(),
which was considered a bad option:
$this->_hasMany('comments', null, 'comment');
The above would mean: assign to $comments the foreign data from the
model 'comment'. It would be necessary to define the foreign model if
you want to use plural ($post->comments). In a case like
$this->_hasOne('blog'), it would assume that, not being defined the
additional parameter, the model will be nuilt based on the same
property name.
Personally, I don't mind about having to define the accessor name and
the related model if I want to use something different (plural) to
call the foreign data, but also I'm not sure if it is simple as that
and this is the only case where a plural would be necessary.
rodrigo
-------------------------------
http://tipos.com.br
More information about the solar-talk
mailing list