Closed glamorous closed 14 years ago
While experimenting with this I found a "bug" or eather way, this wasn't the expected result. In my model I have this:
class Model_Page extends Jelly_Model
{
public static function initialize(Jelly_Meta $meta)
{
$meta->fields(array(
'id' => new Field_Primary,
'seo' => new Field_BelongsTo,
'timestamp' => new Field_Timestamp(array(
'auto_now_create' => TRUE,
'auto_now_update' => TRUE,
)),
'uri' => new Field_Slug,
'name' => new Field_String,
'body' => new Field_Text,
))
->load_with(array('seo'))
->name_key('uri');
}
}
Note the "->load_with(array('seo'))"
When I do this:
echo Jelly::select('page')->select('uri');
I see this query:
SELECT rcc_pages
.id
AS id
, rcc_pages
.seo_id
AS seo
, rcc_pages
.timestamp
AS timestamp
, rcc_pages
.uri
AS uri
, rcc_pages
.name
AS name
, rcc_pages
.body
AS body
, rcc_seo
.id
AS :seo:id
, rcc_seo
.keywords
AS :seo:keywords
, rcc_seo
.description
AS :seo:description
, rcc_seo
.robots
AS :seo:robots
, rcc_pages
.uri
FROM rcc_pages
LEFT JOIN rcc_seo
ON (rcc_pages
.seo_id
= rcc_seo
.id
)
But I expected this:
SELECT rcc_pages
.uri
FROM rcc_pages
Is this the normal behaviour? I expected that the query didn't mind the ->load_with when you use ->select('column')
Can their be an easier way to do this or isn't this an issue to find a workaround?
That's probably the easiest way so far. I don't see many feasible ways to make this shorter.
Regarding your other question:
Is this the normal behaviour? I expected that the query didn't mind the ->load_with when you use ->select('column')
Yes. load_with always does the with(). That's the point of it. I can see how...
SELECT rcc_pages.uri FROM rcc_pages
...might make more sense, but then if load_with is only going to happen under certain circumstances, what are those circumstances?
In any request I do, I need the load_with. Only in this one particular query for my array, I don't need it. For now I deleted my load_with and call it everywhere where I need it (pretty mucht always except that only one :) )
I can live with it this "overload" to code but if their is a solution for it, that should be great ;-)
sounds like you need a 'without()' method :P
Hi,
While developing a site I came accross this "issue". To recieve only one column of a specefic model as array I need this:
As you can see, I say twice that I only need 'posterimg'. Ok this thing should work fine without "->select('posterimg')" but then it would first select all my columns (not such a good thing to performance)
Can their be an easier way to do this or isn't this an issue to find a workaround?