Welcome Guest, Not a member yet? Register   Sign In
[Solved] DMZ and queries.. Please help
#1

[eluser]Unknown[/eluser]
Sorry if this could seem a stupid question but I'm not writing on here for lazyness because I searched a lot around but didn't manage to find a solution to a problem that I'm sure is so banal..

I'm using DMZ 1.4.0 and have and object in my model like this:

<?php
class Town extends DataMapper {

var $table = 'towns';

var $has_one = array(
'province' => array(
'class' => 'province'
)
);

var $validation = array(
array(
'field' => 'name',
'label' => 'Nome',
'rules' => array('required', 'trim', 'alpha_dash', 'max_length' => '255', 'unique')
)
);

function __construct()
{
parent::__construct();
}

function __toString () {
return $this->name;
}
}

/* End of file town.php */
/* Location: ./system/application/models/town.php */


Now I always get and error because the function __toString isn't returning a string value but this is due to the fact that the 'name' column isn't even selected from the database, in fact if I enable the profiler I notice that the query executed is:

SELECT `towns`.`id`
FROM (`towns`)

instead of something like:

SELECT `towns`.*
FROM (`towns`)

Now, how to fix this little thing ?
I'm doing this because I use the render_form method of the htmlform extension of DMZ, to automatically generate a form which fields reflect the validation array of an object. This object has a relation with the 'town' object so I need the render_form to automatically generate a dropdown with all the towns.
Please feel free to suggest me alternative ways if you think I'm approching badly to the problem, I've got a lot to learn and suggestions are very appreciated.

Thanks in advance to everyone

Francesco
#2

[eluser]Unknown[/eluser]
For anyone who could be experiencing the same problem.. I've solved it.
It was due to the fact that in the object model which I wanted the form generated for I specified the has_one relation with town but in the town object model I didn't specify the has_many relation with the other object. Adding this inverse relation did the trick..

Hope this could save some time to anyone as it took me the whole day to figure it out..




Theme © iAndrew 2016 - Forum software by © MyBB