Status update: ActiveRecord
Posted 08 June 2012 - 10:46 AM
@this and @that
@self and @foreign
@self and @other
@self and @related
@self and @link
@self and @rel
@this and @rel
@me and @rel
Posted 11 June 2012 - 09:29 AM
Trying to imagine myself in the place of a Yii learner, i gotta disagree. @rel is almost as cryptic as the original proposal of @ and ?.
Of all the proposals made so far, i think
are most likely to be readily understood by a noob.
Saving 4 characters isn't worth it.
Posted 11 June 2012 - 09:43 AM
In Qiang's first post in this thread, he said "?." can be used "in queries and scopes to represent the table alias prefix to columns" and that it represents "the foreign table". This makes me wonder how (if at all) it applies in a query/scope where we have more than one foreign/related table. Take the following example:
// Yii 1.1 syntax. // Find all posts for a public blogs and where the author's account is still active (whatever that means in this example). Post::model()->with('blog', 'author')->findAll('blog.is_public=true and author.is_active=true');
// Yii 2.0 syntax (attempt). // Find all posts for a public blogs and where the author's account is still active (whatever that means in this example). Post::find()->with('blog', 'author')->where('blog.is_public=true and author.is_active=true')->all();
So in the above example, is "?." applicable, and if so what foreign/related table would it reference?
This is a good question!
In a relation spec, @foreign clearly has a role.
But in other contexts, is there a use for a shorthand for one of the relation names in the global relation namespace? How do I (and AR) know which it refers to?
In Yii 1.1 AR, queries and scopes can be used with zero, 1 or more related models. Unless Yii 2 AR has methods specifically for using 1 specified related model, where's the opportunity to use @foreign?
Posted 11 June 2012 - 01:37 PM
What? No. We're using a technique called related Active Records. Used to fetch related entries from the database. related -> @rel. Easy to remember, fast to type. Really can't share your view on that.
Posted 11 June 2012 - 02:25 PM
Posted 11 June 2012 - 02:48 PM
Posted 12 June 2012 - 08:10 AM
Either all this discussion over a better name for ?. is stupid or rAWTAZ and I are stupid. (no disrespect
Does anyone have some insight on what ?. is used for other than in a relation definition?
Posted 13 June 2012 - 12:02 AM
It seems like we pick less important design solution from the Qiang's post and have a lot of buzz about it.
For Yii newcomers it is absolutely not necessary to use such things. Placeholders can be extremely useful when writing unified code such as active record behavior to avoid hardcoding of table names or configuration for table names. And writing behaviors is not what new users will start from.
So I think original proposal (@ and ?) is good.
Regarding the use of "?" - as I remember there was such feature in Yii 1.0 where we had aliasToken in CActiveRelation class, so we could use something like "??.name" to refer related table column.
And (I may be wrong) it only worked when you have one relation - in other cases you had to set aliasToken properties for relations manually. So I guess here we can have similar situation - '?' will work only when one related table is involved.
Posted 13 June 2012 - 03:07 AM
Posted 15 June 2012 - 02:15 AM
If I where to define these keywords, according to the user experience and interaction principles I would definitely go for @self and @related/@linked
@related is self explanatory for anyone that knows what a foreign key relationship is. it's easy to write for non native English speakers, and the keys are grouped near on the keyboard.
@linked could be an option, but again, related is better in my opinion, because of the consistency with SQL language.
@foreign easier to understand than @related, but MUCH more difficult to write even for native English speakers; GN NG endings on words are hard to discriminate for most non natives, also EI IE is a problem for many non natives because of accent and pronunciation.
@rel doesn't offer any real advantages over "?", opens up to subjective interpretation and confusion.
@self is self explanatory, easy to write and it's consistent with PHP/YII language dynamics.
@this can cause confusion because it can easily be taken out of context, and it's not any easier to write than "self".
I hope this helps out!
Posted 15 June 2012 - 02:53 AM
Posted 15 June 2012 - 05:17 AM
A group of people give weight to trivial issues, obscuring the important issues at hand. This occurs because the important issues generally require significant domain knowledge or complicated mental evaluation, whereas the trivial issues are by definition trivial and therefore it's easy to have an opinion one way or the other.