#12 ✓invalid
miracle_bg

Help :(

Reported by miracle_bg | August 13th, 2009 @ 05:00 PM

ActiveRecord is an insanely easy to use database ....

Stop at 'insanely easy' ..

Dear devs...

i've been trying to port the lib to one of my objc projects.... so far .. i managed to connect..use base methods for working with data on a single objects but...

I cannot figure out how to use relationships..

The examply you have given on the Git site..is ... well ... not enough.

At least a basic document covering the general features - like relationships is a must.

I dag into the source code ... i am not even sure if relationships are even complete - as to be used at this moment?

Any replies will be greatly appreciated as i am starting to already loose confidence that the job can be done with activerecord for objc...

Thank you!
Martin K.

Comments and changes to this ticket

  • Fjölnir Ásgeirsson

    Fjölnir Ásgeirsson August 13th, 2009 @ 05:13 PM

    • Assigned user cleared.
    • State changed from “new” to “invalid”

    Ok, "porting the lib to"? do you mean "use the framework in"?
    is this an iPhone project or a Mac app?
    if it's a mac app you just need to compile the framework and add it to project, also create a build phase to copy the framework into the bundle before you distribute

    has many through is not complete. But all the basic relationships are there.

    The example on the site is meant for people already confident in developing on the mac. Do you have much experience in Cocoa?

  • miracle_bg

    miracle_bg August 13th, 2009 @ 05:23 PM

    Thanks for the quick response! :) I thought the project might be abandoned at first ... coolness it's not :)

    We are two cocoa developers - creating a portable app for both iPhone and mac osx.

    The problem is how to use the relationships under objc - as related to Rails...

    Figuring out how to specify the model's members is already in the example you provided - but how do you link together the models with relationships? Is this semi-automatic based on detecting model's member's names? I guess no??

    In Rails you can say: has_many :employees or belongs_to: whatever.

    How do we specify the relationships with this framework?

    Is there something simple as a sample that you can post somewhere - i guess it will help others too :)

    Just an example:

    Tables: Collections, Categories
    Models: Collection, Category

    There are many 'categories' in many 'collections'. How would we specify this in the model?

    Thank you again for your time!

  • Fjölnir Ásgeirsson

    Fjölnir Ásgeirsson August 13th, 2009 @ 05:32 PM

    Heh, I forgot to put the relationship examples in the example did I? =)
    well if you read the unit tests (they're in the repository), there's lot's of examples there

    Like this one:

    @implementation TEPerson
    @dynamic userName, realName;
    + (void)initialize
    {
      [[self relationships] addObject:[ARRelationshipBelongsTo relationshipWithName:@"model"]];
      [[self relationships] addObject:[ARRelationshipHABTM relationshipWithName:@"animals"]];

    [[self relationships] addObject:[ARRelationshipHasMany relationshipWithName:@"belgians"]];
    
    
    
    
    } @end
    that would be equal to:
    class Person
      belongs_to :model
      has_and_belongs_to_many :animals
      has_many :belgians
    end
    

    Also, the project isn't "abandoned" but I'm not actively working on it myself anymore, not a high school student anymore^^
    but there's been some guys contributing lately. Also, if you use it in your project and add any features / fix bugs feel free to fork the project on github so I can merge it later

  • miracle_bg

    miracle_bg August 13th, 2009 @ 08:07 PM

    • Assigned user set to “Fjölnir Ásgeirsson”

    Thanks a bunch!

    I figured things out now.

    I saw something strange though.

    I enabled logging in the low level where the queries get executed and this:

    NSArray *xxxx = [[[[[[StCollection find:ARFindFirst] objectAtIndex:0] categories] objectAtIndex:0] cards] objectAtIndex:0];

    resulted to this:

    2009-08-13 21:56:34.690 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT id FROM collections LIMIT 1 subs: {

    id = -1;
    

    } 2009-08-13 21:56:34.697 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT id FROM categories WHERE collectionId = :our_id subs: {

    "our_id" = 1;
    

    } 2009-08-13 21:56:34.700 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT id FROM cards WHERE categoryId = :our_id subs: {

    "our_id" = 1;
    

    } 2009-08-13 21:56:34.703 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT id FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.704 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT categoryId FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.705 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT collectionId FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.705 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT objectId FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.706 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT objectOid FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.706 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT audioCount FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.707 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT videoCount FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.708 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT imageCount FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.708 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT dateCreated FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.709 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT elemOrder FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.710 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT title FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.710 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT frontImageOid FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.711 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT frontVideoOid FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.712 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT info1 FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.712 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT info2 FROM cards WHERE id = :id subs: {

    id = 1;
    

    } 2009-08-13 21:56:34.713 sample-test-stampii-active-record[84506:10b] Executing SQL: SELECT info3 FROM cards WHERE id = :id subs: {

    id = 1;
    

    }

    Why is every single field of the table - CARDS - being fetched with another query? This puts a lot of overhead to the database fetching ... is it a bug or an intentional 'feature'?

    Thanks, again!

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

ActiveRecord is an insanely easy to use database framework written in objective-c It's obviously "inspired" by (copying) the infamous ActiveRecord that comes with Rails(http://rubyonrails.org) But it tries to be more versatile when it comes to working with multiple connections.

People watching this ticket

Pages