Welcome Guest, Not a member yet? Register   Sign In
DMZ 1.7.1 (DataMapper OverZealous Edition)

[eluser]bonatoc[/eluser]
@Wazzu

I think kre8ivdesigns is correct.

Then you can access your users data like this :

$the_user_id = $i->user->id;
$the_user_name = $i->user->name;
$the_user_email = $i->user->email;
...

Obviously you'll make your own vars depending on the table's columns.

You can state :

$array_of_users = $i->user->get();

and then pass the array to your view to fetch it.

[eluser]Wazzu[/eluser]
Thanks, guys.
Finally I've tried this way and seems to be generating the right sql:

Code:
$u = new User();
$u->select_sum_related('invoice', 'total');
$u->group_by('id');
$u->having('total >', '100');
It's quite clear and lets me get more data from models related with my User model

[eluser]kre8ivdesigns[/eluser]
For some reason I cant get my data to delete....

Code:
function delete_rate($id)
    {
        //delete the individual rate and days associated with it
        $d = new Day();
        $d->get();
        
        $r = new Rate();
        $r->where('id',$id);
        $r->get();
        
        $r->delete($d);
    
    }

It will delete my rates and days_rates information but not the days information

[eluser]OverZealous[/eluser]
kre8ivdesigns
You don't have to go through all of that. DMZ automatically deletes the relationships when you delete the item. Just do $rate->delete() and it will delete the item.

Please read the manual a little more thoroughly before posting. Many of your questions are easily resolved by looking through the manual and the examples included. For example, see the bright yellow section on the Delete page in the manual to see how delete works.

[eluser]kre8ivdesigns[/eluser]
I did read it and when I did $rate->delete(); it deletes the rates and the days_rates table but not the days table.

I have read every page of the manual and go to that first. Thanks for the help.

UPDATE:

This works but is there a better using DMZ:
Code:
$rate = new Rate();
        $rate->where('id',$id);
        $rate->get();
        foreach ($rate->day->get() as $row)
        {
            $d[] = $row->day;
        }
        $count = $rate->day->count();
        $rate->delete();
        
        $date = new Day();
        for($x=0; $x < $count; $x++)
        {
            $date->where('day',$d[$x]);
            $date->get();
            $date->delete();
        }

[eluser]WanWizard[/eluser]
[quote author="kre8ivdesigns" date="1282025670"]I did read it and when I did $rate->delete(); it deletes the rates and the days_rates table but not the days table.[/quote]
That is quite logical.

You have a many-to-many relationship between Rates and Days, using a relationship table. That means that for any given Day record, you could have multiple rates. Deleting day records when deleting a rate would be corrupting your database, as it will orphan orher rates linked to that day.

If there is no many-to-many, then your database design is wrong.

[eluser]serhat[/eluser]
What is your deadline for CI 2.0 ?

[eluser]OverZealous[/eluser]
@serhat
It's not even on my timeline. I don't have any time to work on DMZ right now. Sorry.

Besides, DMZ should work fairly well as is. Many users have been experimenting with CI2 for a while now.

I'm in the middle of a major move, and will be for the foreseeable future.

[eluser]kre8ivdesigns[/eluser]
Ok I understand what you mean.

Orginally I thought if I am going to change the rate I need to delete the rate and dates, but in reality I just need to update the rates and I am creating a function that can update individual dates with a rate.

Thanks for the help.

This is my first attempt at building a database and writing PHP. Thanks for not getting too fustrated with my questions.

[eluser]dejavu[/eluser]
[quote author="bee27" date="1281937699"]Hi,

I'm relatively new to CodeIgniter and DMZ, but have come across a strange issue, and I'm not sure if its me or a bug...

I have models Site and Page. Site can have many Pages, and Pages can have one Site. The pages table has the site_id, rather than a joining table.

I run the following code, to get the first page for the site...

Code:
$page = $s->page->where('order', 0)->where('visible', 1)->get();

and the SQL is ...

Code:
SELECT `pages`.*
FROM (`pages`)
WHERE (
`pages`.`order` = 0
AND `pages`.`visible` = 1
)
AND
        `pages`.`site_id` = 4

... which is correct.

Then I do the following, to get all pages for the site (to build a navigation list) ...

Code:
$pages = $s->page->where('visible', 1)->get();

... and the SQL is ...

Code:
SELECT *
FROM (`pages`)
WHERE `pages`.`visible` = 1

... the where clause for the site_id seems to be missing, so all pages for all sites get returned!

Am I doing something wrong, do I need to reset something before running the 2nd query? Strangely if I swap the order of the two calls the 2nd always misses out the site_id where clause.
[/quote]

Datamapper will clear the object between queries. I wouldn't be surprised if it accidentally clears the setting relating it to $s/site.

One thing you could try is caching the query. This isn't caching the query results, but caching the assembled SQL. See if that solves the problem of the object being cleared.




Theme © iAndrew 2016 - Forum software by © MyBB