Coder Social home page Coder Social logo

alexdenisov / iactiverecord Goto Github PK

View Code? Open in Web Editor NEW
354.0 22.0 50.0 1.3 MB

ActiveRecord for iOS without CoreData, only SQLite

Home Page: http://alexdenisov.github.com/iActiveRecord/

License: MIT License

Objective-C 18.25% Ruby 0.17% Objective-C++ 18.44% C 61.06% C++ 2.09%

iactiverecord's Introduction

The project is looking for maintainer

ActiveRecord without CoreData.

Only SQLite.

Only HardCore.

Build status

This repo available on Twitter.

Features

  • ARC support
  • unicode support
  • migrations
  • validations (with custom validator support)
  • transactions
  • support for custom data types
  • relationships (BelongsTo, HasMany, HasManyThrough)
  • sorting
  • filters (where =, !=, IN, NOT IN and else)
  • joins
  • CocoaPods support
  • no more raw sql!!!

You do not need to create tables manually - just describe your ActiveRecord and enjoy!!!

#import <ActiveRecord/ActiveRecord.h>

@interface User : ActiveRecord

@property (nonatomic, retain) NSString *name;

@end

Run tests

iActiveRecord uses Cedar for UnitTests and CocoaPods for dependency management. Follow this steps to run tests

[sudo] gem install cocoapods
pod setup
cd project_dir
pod install
open iActiveRecord.xcworkspace

Then build & run UnitTests target.

Check Wiki to see details!

Bitdeli Badge

iactiverecord's People

Contributors

alexdenisov avatar alexu84 avatar berikv avatar bitdeli-chef avatar claudotp avatar danpe avatar fedefrappi avatar fleitz avatar jklimke avatar mgod avatar neilabdev avatar rofreg avatar x0000ff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iactiverecord's Issues

Problem when use NSDictionary

Hi,

With the current version i found one problem.

When i create one NSDictionary with json data of my webservice and set it into my ActiveRecord classes, it dont accept its values, because it i converted in primitive types.

Example:

// chapterListItem is the NSDictionary object, and it only accept objects (NSString and NSNumber)
MyProductChapter *chapter = [MyProductChapter newRecord];
chapter.chapter_id = [chapterListItem objectForKey:@"chapter_id"]; //chapter_id is NSNumber in activerecord class
chapter.object_id = [chapterListItem objectForKey:@"object_id"]; // object_id is NSString in activerecord class
[chapter save];

Both chapter_id and object_id is an object (NSNumber and NSString).

But is an object that store a number, and when i set this objects into my MyProductChapter class that inherit from ActiveRecord, it convert it to "int" and on method "save" i got error.

ARDatabaseManager.mm LINE: 472

When is INT (the column value referenced by variable "id value = [aRecord valueForColumn:column]"), on the line:
if ([value isKindOfClass:[NSNumber class]]) { , throws the exception (Line: 482).

It doesnt happen before the update. Everything is working fine.

Attempt to mutate immutable object with appendFormat:

Using the following lines:

    ARLazyFetcher* fetcher = team.users;
    User* asker = [self asker];
    if (asker != nil) {
        [fetcher where:@"'user'.'serverUserId' != %@", asker.serverUserId, nil];
        return fetcher.fetchRecords;
    }

crashed from
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with appendFormat:'

on

[fetcher where:@"'user'.'serverUserId' != %@", asker.serverUserId, nil];

SQL Injection

Hi,

After i use it on my projects, users can write a note on his bookmark on my app. The problem is when users type something like:

Text: "a new bookmark" my bookmark

The iActiveRecord doesnt escape charcters. But i thing that the best solution is rewrite the queries using parameters instead of create all the query and bind on hand.

Can you solve it?

Alters

Would be nice to implement alters for tables so if u want to add new field it will not kill database.
Simple scenario: User have app installed and data is stored in documents dir. You releasing an update with few extra fields in Users table.

Leaks with NSDate

Faced with such a problem: with each operation with a base leak. Xcode Instruments indicates iActiveRecord [NSDate dateWithTimeIntervalSince1970:] and [NSDate dateWithTimeIntervalSinceNow:]

//on the Russian
Столкнулся с такой проблемой: при каждой операции с базой происходят утечки. Xcode Instruments указывает на iActiveRecord [NSDate dateWithTimeIntervalSince1970:] и [NSDate dateWithTimeIntervalSinceNow:]
leaks

Crash on database creation

Hi,

I started implementing this framework in a project and for some reason it seems to crash at the database creation (I think during the tables creation).
Then once it has crashed once (and the empty database was created) it work but I have this error :
Couldn't retrieve data from database: no such table: Account

Here are my models, nothing really fancy about them.

@interface Account : ActiveRecord

@property (strong, nonatomic) NSNumber * accountId;
@property (strong, nonatomic) NSString * firstName;
@property (strong, nonatomic) NSString * lastName;
@property (strong, nonatomic) NSString * phone;
@property (strong, nonatomic) NSString * gender;
@property (strong, nonatomic) NSDate * birthDate;

has_many_dec(Prescription, prescriptions, ARDependencyDestroy)
@end


@implementation Account

@synthesize accountId;
@synthesize firstName;
@synthesize lastName;
@synthesize phone;
@synthesize gender;
@synthesize birthDate;

has_many_imp(Prescription, prescriptions, ARDependencyDestroy)

@end

@interface Prescription : ActiveRecord

@property (strong, nonatomic) NSNumber * prescriptionId;
@property (strong, nonatomic) NSNumber * accountId;
@property (strong, nonatomic) NSString * picture_name;
@property (strong, nonatomic) NSDate   * date;
@property (strong, nonatomic) NSString * message;
@property (strong, nonatomic) NSDate   * reply_date;
@property (strong, nonatomic) NSString * reply_message;
@property (strong, nonatomic) NSNumber * statusCode;
@property (strong, nonatomic) NSNumber * archived;

belongs_to_dec(Account, account, ARDependencyDestroy)

@end


@implementation Prescription

@synthesize prescriptionId;
@synthesize accountId;
@synthesize date;
@synthesize picture_name;
@synthesize message;
@synthesize reply_date;
@synthesize reply_message;
@synthesize statusCode;
@synthesize archived;

belonsg_to_imp(Account, account, ARDependencyDestroy)

@end 

I could use a hint :/

errors building on XCode 5.1

Hi, i'm having a series of issues (see image attached) trying to build the framework on XCode 5.1.
Have you managed to build for ios7/code 5 or is it still on the run?

Thanx
G.
schermata 2013-10-31 alle 13 46 06

Change the default table name

Hello,
could it be possible to change the default table name?

I mean, let's suppose I have a prepopulated SQLite database with a table called "users_phones".

To have this working with this library (as far as I know) you have to create an objective-c class called exactly "users_phones". But I want this class to be called "UsersPhones" as any other class in objective-c.

So it could be great to call the class "UsersPhones" and tell the class to load the table "users_phones" instead of searching for the table "UsersPhones" or create one.

Congratulations for this great piece of code. It is really amazing!

Thanks a lot!

sqlite3_unicode.h Compile Error

Hi,

I am just trying out iActiveRecord with a brand new project. I installed iActiveRecord 1.1.2 with CocoaPods.

When I compile, ARDabaseManager complains that 'sqlite3_unicode.h' is not found. I notice that sqlite3.0.dylib wasn't included in either the main project or the Pods project. So I added it to the link with binary Build Phase. But I get the same compile error. Any advise please?

Thank you,

Norsez

Relationship setter names

Hi,

This project seems very interesting!

Anyway, it seems that to avoid providing getter name with its first letter capitalized as setter name,
_ar_registerBelongsTo##class and set##class uses 'class' for their method names,
but it is possible that one has more than one relationships to a class.

So I think it might be better to use something like
belongs_to_dec(class, getter, Getter, dependency)
for generality.

Is there any other reasons why 'class' is used for those names?

Thanks

Shunpei

Crash on x64 architecture

Hello!
When I run the projects on 64bit simulator, I get crashes.

In one project it is

//  ARLazyFetcher.m
...
- (ARLazyFetcher *)where:(NSString *)aCondition, ...{
...
NSString * result = [[NSString alloc] initWithFormat:aCondition
                                               arguments:data.mutableBytes];
...

In the other project the crash is in

//sqlite3_unicode.c file
...
/*
** <sqlite3_unicode>
** The following function is the default entry point of an SQlite extension built as a
** dynamically linked library. On calling sqlite3_load_extension() sqlite3 will call
** this function to initialise unicode functionality.
*/
#ifndef SQLITE_CORE
SQLITE_EXPORT int sqlite3_extension_init(
  sqlite3 *db, 
  char **pzErrMsg,
  const sqlite3_api_routines *pApi
){
  SQLITE_EXTENSION_INIT2(pApi)
  return sqlite3_unicode_init(db); // crashes here
}
#endif

Please let me know if any of them do reproduce on your station as well.
Thank you in advance!

Problems on linking iActiveRecord to my App

Hi,

I have downloaded the ZIP from github with source and i try install it to my project, but i get the error above:


Ld /Users/paulo/Library/Developer/Xcode/DerivedData/uBook-chcabrasmyhbfccdfgginmrzdgqw/Build/Products/Debug-iphonesimulator/uBook.app/uBook normal i386
cd /Users/paulo/Documents/workspaces/xcode/ubook
setenv IPHONEOS_DEPLOYMENT_TARGET 5.0
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk -L/Users/paulo/Library/Developer/Xcode/DerivedData/uBook-chcabrasmyhbfccdfgginmrzdgqw/Build/Products/Debug-iphonesimulator -F/Users/paulo/Library/Developer/Xcode/DerivedData/uBook-chcabrasmyhbfccdfgginmrzdgqw/Build/Products/Debug-iphonesimulator -F/Users/paulo/Documents/workspaces/xcode/ubook/libs -filelist /Users/paulo/Library/Developer/Xcode/DerivedData/uBook-chcabrasmyhbfccdfgginmrzdgqw/Build/Intermediates/uBook.build/Debug-iphonesimulator/uBook.build/Objects-normal/i386/uBook.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=5.0 -framework ActiveRecord -lsqlite3 -framework AVFoundation -framework QuartzCore -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/paulo/Library/Developer/Xcode/DerivedData/uBook-chcabrasmyhbfccdfgginmrzdgqw/Build/Products/Debug-iphonesimulator/uBook.app/uBook

Undefined symbols for architecture i386:
"OBJC_CLASS$_ARConfiguration", referenced from:
objc-class-ref in ActiveRecord
ld: symbol(s) not found for architecture i386

clang: error: linker command failed with exit code 1 (use -v to see invocation)

The steps:

1 - Download zip from github
2 - Extract the zip
3 - Open the project into xcode (osx 10.8 and xcode 4.6.2)
4 - Build the project "Build_Framework" for iPhone Device
5 - Open Finder and go to extracted path (step #2) + "Products"
6 - Copy "ActiveRecord.framework" to my project path + "libs" (project/libs/ActiveRecord.framework)
7 - Open my project on xcode
8 - Add framework: my project path + "libs" (project/libs/ActiveRecord.framework)
9 - I already have sqlite3.dylib into my project and it is working, dont need add again
10 - Compile my project for iPhone Device
11 - Got the error ^^

:::SCREENSHOT:::

screen shot 2013-06-19 at 2 41 11 pm

NSArray SQL representation

Hey,

First of all, thanks for the great library. I plan on contributing some, I've started to make a set of methods I've found useful in my project that I'll pull request at some point so you can take a look.

I have a question about SQL representation. You have this in the wiki:

@implementation NSString (sqlRepresentation)

+ (ActiveRecord *)fromSql:(NSString *)sqlData{
    return sqlData;
}

- (NSString *)toSql {
    return self;
}

+ (const char *)sqlType {
    return "text";
}

@end 

You have fromSql returning ActiveRecord, would it not return NSString? Am I misunderstanding how this works?

I'm setting up sql representation for NSArray. All array will just contain BOOLs, something like this:

NSArray *values = @[ @YES, @NO, @NO, @YES ];

My storage technique is just to serialize the data as JSON and back again. Here's the code:

@implementation NSArray (BBExtension)

+ (id)fromSql:(NSString *)sqlData{
    return [NSJSONSerialization JSONObjectWithData:[sqlData dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
}

- (NSString *)toSql {
    return [NSString stringWithUTF8String:[[NSJSONSerialization dataWithJSONObject:self options:0 error:nil] bytes]];
}

+ (const char *)sqlType {
    return "text";
}

@end

I've tested the serialization/deserialization to verify that when I manually do it, it works fine. But when creating the record like so:

BBGroove *groove = [[BBGroove alloc] init];

...

[groove save]; // This returns YES

NSLog(@"Groove: %@", [BBGroove allRecords]);

After the NSLog runs, I get this in the console:

2012-07-29 19:54:55.896 BeatBuilder[3479:c07] SELECT "BBGroove"."id","BBGroove"."updatedAt","BBGroove"."beatUnit","BBGroove"."beats","BBGroove"."tempo","BBGroove"."createdAt","BBGroove"."voices" FROM "BBGroove"  LIMIT -1 
2012-07-29 19:54:55.897 BeatBuilder[3479:c07] Couldn't retrieve data from database: no such table: BBGroove
2012-07-29 19:54:55.923 BeatBuilder[3479:c07] Groove: (null)

My other models work just fine, but this one model has the custom ARRepresentationProtocol for arrays and doesn't work, so I can't help but think I might be doing something wrong? Do you see something I'm overlooking?

I'll keep looking into it, but wondered if you had some insight. Thanks for the great work!

Duplicate Symbols using NSData+Base64 (Replace with Pod)

Excited about using iActiveRecord. I did notice that a common lib, NSData+Base64 is used by a lot of libraries, including MKStoreKit, causing duplicate Symbols. If you use add 'NSData+Base64' as a dependency, it should resolve the issue with other libraries if they did the same. Though in my case, even if this was done, it would not solve my issue because though MKStoreKit renames the category, the static methods have the same name :(

  pod 'NSData+Base64'

Problem when change the table name to the same class

I see one problem recently.

When we change the table name in recordName method,  ex: before the table name is "abc" and after i change the table name for the same class to "abcdef", i get a crash when the app initialize and we call that method to connect to database.

pseudo-code:

before

product {
    String recordName {
           return 'abc';
    }
}

after:

product {
    String recordName {
           return 'abcdef';
    }
}

The correct behavior is the creation of first table, "abc". When i change the table name, another table need be created "abcdef" and the code will use it. I dont know why, but after the first table was created, if i change the string of recordName method, i get a crash when i call that method that initialize the database on AppDelegate.

I dont know if a reference for that table in that class is store in someplace, but something wrong happen.

Looking for maintainer[s]

As I mentioned in README the project is discontinued, because I don't have enough time to maintain and develop new versions.

If I continue, then I'd better start the project from scratch or change it radically, e.g.: protocols instead of inheritance; explicit conventions (names or special classes for relationships between entities) over preprocessor definitions; more abstract 'engine' implementation, with possibility to easily switch between sqlite versions (3,4) or even different DB engines. And of corse much more tests!

These tasks need a lot of time, which I don't have.

But still I see some activity around the project (does somebody really use it?):

I'd like to ask community for a favor:

Please, let me know if you're interested in maintaining and developing of this project!

Save doesn't work

I have code, much like:

Properties: _id, _rev, site (all NSString), jsonRepresentation (NSData)

SomeRecord *sr = [SomeRecord newRecord];
sr._id = @"something";
sr.site = @"mine";

[api doStuff:^(NSDictionary*)r {
  NSError *err;
  sr.jsonRepresentation = [NSJSONSerialization dataWithJSONObject:r options:kNilOptions error:&err];
  sr._rev = r[@"_rev"];
 [sr save];
}];

But while I can log, just before [sr save] the values of sr._id and sr.jsonRepresentation and they are all correct, logging the object itself shows that its idea of reality is clearly inconsistent:

_id => (null);_rev => 3-d502435ac80cc2b3fd78facdc2399e51;site => (null);jsonRepresentation => (null);id => (null);updatedAt => (null);createdAt => (null);

Table name not lowercase (as specified in documentation)

Hi Alex,

I have a model User:ActiveRecord, and I need to get rows from an already existing database with a table user.
Problem is : iActiveRecord is creating (and thus expecting) a table named User instead of user.

Any way around that?

Thanks for your time.

NSDecimalNumber and new primitive types

Hey Alex,

I think iActiveRecord should use a different method for dealing with NSDecimalNumber now that primitive numeric types are available. Now that you can have floating point values through a method other than NSDecimalNumber, I think we should move to using NSDecimalNumber for currency only (which is really what it's there for). Given this, we should really store NSDecimalNumbers as string values in sqlite to keep the base-10 math precision correct.

I'm happy to go ahead and write up a patch if this sounds reasonable to you.

Marshall

Android support

Please implement an Android version of your awesome library in Java

Reload the databse file

Hello,
I am programming an app that downloads a new version of a database SQLite file anytime it needs to update. The problem is that ActiveRecord seems not to respond until I quit and close the applicacion and get back in again.

It could be possible to reinitialize the ActiveRecord database with the updated database SQlite file?

I've tried calling the +[ActiveRecord registerDatabaseName....] after the databse file is updated in the NSDocumentsDirectory but it's not working for me.

Am I missing something? (probably I am). Any help would be great! Thank you so much!

Problem when get elements that are NSNumber

Hi,

I found a small problem when you fetch data from database, and the column is "NSNumber".

Instead of come a "NSNumber" with a "int" value, it come with a "NSString" value.

You need have a field that is NSNumber. Insert any data and retrieve. When you debug and inspect the column that you retrive, you will see @"1", instead of 1 (int).

The problem occurs when I according the Readme

I according the Readme, I have gotten a " -[User setName:]: unrecognized selector sent to instance 0x68896a0" error,

e.g. in the case:
User *user = [User newRecord];
user.name = @"Alex";
[user save];

NSArray *users = [User allRecords];
User *userForRemove = [users first];
NSLog(@"%@",userForRemove.name);

Handle ActiveRecord serialization

I'd like to save database content in serialized format.
For now, using SBJSON, is get this error :

-JSONRepresentation failed. Error is: JSON serialisation not supported for <MyActiveRecordClass>

Is there a way to circumvent this?

NSDate column values are returned as _NSCFNumber* objects

Hi,

i noticed when i tried to work with the updatedAt and other date fields, that the values returned from NSDate* getters are in fact of type NSCFNumber*

here is an excerpt of a xcode debugger session. the field lastUpdate is a NSDate* property.

self PNOfferUpdater * 0xc080480 0x0c080480
NSObject NSObject
_delegate PNOfferListViewController * 0xc07e580 0x0c07e580
_groups NSArray * nil 0x00000000
_groupOffers __NSDictionaryM * 0 key/value pairs 0x0c085220
_updateInterval NSTimeInterval 0 0
lastUpdate __NSCFNumber * (double)1.38669e+09 0x0c0815b0
updateRun PNOfferUpdate * 0xc07f160 0x0c07f160
ActiveRecord ActiveRecord

After a little more debugging i found out that the toColumnType method of the NSDateColumn directly returns the value that was passed to the method. I think it should return an NSDate object made out of the nsnumber-object passed.

Multiple saves don't update

I noticed this in my own project, and made a small project to demonstrate that you can download here: http://d.pr/f/1EQq/1NHJehlq

It's using the version in cocoapods. The main code is essentially this:

    TTModel *model = [TTModel newRecord];

    model.someNumber = @1;

    // 1 is saved to the database
    [model save];

    model.title = @"Foobar";

    // "Foobar" is NOT saved to the database here
    [model save];

    model = [[[TTModel lazyFetcher] fetchRecords] first]; // Reload the model

    NSLog(@"Title: %@ should be 'Foobar'\nNumber: %@ should be 1", model.title, model.someNumber);

Which prints out the following:

Title:  should be 'Foobar'
Number: 1 should be 1

Notice that model.title is an empty string after retrieving it from the DB. If you put a print statement inside the executeSqlQuery method, it never executes an UPDATE. My guess is this has to do with tracking dirty/changed attributes, but it's hard to say for sure.

make name format of foreign key columns definable

Currently it seems to me that foreign keys for the database are always assumed to be in CamelCase. it would be nice if this could be configured somehow.

E.g. if you have a Contact-Model and an Address model like the following, the foreign key must (???) be like referencedModeNameId and cannot be called referenced_model_name_id.

@interface Contact : ActiveRecord

@property NSString* phone;
@property NSString* email;
@property NSString* name;
@property NSNumber* addressId;

belongs_to_dec(Address, address, ARDependentDestroy);

@end


@implementation Contact

@dynamic name, phone, email, addressId;

belongs_to_imp(Address, address, ARDependencyDestroy)

@end 

@interface Address : ActiveRecord


@property NSString* streetLine1;
@property NSString* streetLine2;
@property NSString* zip;
@property NSString* city;
@property NSDecimalNumber* lat;
@property NSDecimalNumber* lon;



@end

@implementation Address


@dynamic streetLine1, streetLine2, zip, lat, lon, city;
@end

If this could be changed (optionally), you could easily use a small Rails application to e.g. build a content database to feed you application. That means i would like to have a foreign key like ´´´address_id´´´to be generated

Would this be easily possible ?

ARValidatorPresence crashes

Hello. I am having a problem and I want a fresh look on this.
I have some ActiveRecord entities in my application and both the application / specs (using cedar) targets are crashing (randomly - can happen 3 times in a row, can happen once in a week). And that crash is being traced from the calls:

-[ActiveRecord save]
-[ActiveRecord isValid]
+[ARValidator isValidOnSave:]
-[ARValidator isValidOnSave:]
-[ARValidatorPresence validateField:ofRecord]

It happens on random fields, on random classes.

The cause of the crash is [NSObject(NSKeyValueCoding) valueForKey:]
I get an EXC_BAD_INSTRUCTION, code is EXC_i386_INVOP, subcode=0x0 on line:

id aValue = [aRecord valueForKey:aField]

from the ARValidatorPresence's validateField:ofRecord:method.
It has been bugging me for complete weeks and months and I could not find a solution for it. Do any of you know what could be possibly going on?
Also, the database does not initialize if sqlite3_unicode_load() is executed. (Please note that I've also commented that out, may that be the cause?) (Please don't get harsh on me, I've just did my best to make it work.)
Also, if I remove validate_presence_of from the entities validation, everything works OK.
Also, I've made specs coverage for the iActiveRecord specs, and some of classes like ARColumn or core columns are not fully covered by specs.
I would really love to get any directions on this, please let me know if I should provide any additional info, thanks in advance!

I could not get data from blob field

I have a database,the database schema is : create table "card"(id integer primary key unique , "title" text, "type" text, "body" blob,"updatedAt" INTEGER, "createdAt" INTEGER) ,and body field already has some of the binary data.
I copy the database to the Documents.
Here is my code:
@Property (nonatomic, retain) NSData *body;
NSArray *cards = [Card allRecords];
Card *card = [cards first];
NSLog(@"%@",card.title);
NSLog(@"%@",card.body);

I can get the title,but the body is nil

belongs_to id naming conventions

I've found what appears to be naming inconsistencies in relationships, though I may just be doing something wrong. I have the following code settings up a has_many relationships where BBSongs have_many BBGrooves:

// BBSong.h
@interface BBSong : ActiveRecord
    ...
    has_many_dec(BBGroove, grooves, ARDependencyDestroy)
@end

// BBSong.m
@implementation BBSong
    has_many_imp(BBGroove, grooves, ARDependencyDestroy)
@end

// BBGroove.h
@interface BBGroove : ActiveRecord
    ...
    belongs_to_dec(BBSong, song, ARDependencyDestroy)
@end

// BBGroove.m
@implementation BBGroove
    belongs_to_imp(BBSong, song, ARDependencyDestroy)
@end

// main code
BBSong *song = [BBSong newRecord];
song.title = @"Foobar";
[song save];

BBGroove *groove = [BBGroove newRecord];

[song addBBGroove:groove];

NSLog(@"All grooves: %@", [BBSong first]);

ARLazyFetcher *fetcher = [song grooves];

NSLog(@"Song's groove: %@", [fetcher fetchRecords]); // This is where the error is thrown, in fetchRecords

I get this error:

2012-08-01 21:11:08.035 BeatBuilder[32686:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<BBGroove 0x8a70c20> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key bBsongId.'

So I noticed its doing its own camelcase sort of thing, so I kept looking into it. Inside ARLazyFetch.m in the buildSql method, I printed out the SQL and it looks like this: http://d.pr/i/DCv4/2DbVKVRz

Notice that in the SELECT it's bBSongId, but in the WHERE it's BBSongId, which seems inconsistent.

I kept going, and inside the allRecordsWithName:withSql: method, I stopped it at the association: http://d.pr/i/DU2l/1drZqAQA

Notice that the propertyName is bBsongId, a third variation. I'm looking into it some more, but I just wanted to get my findings up as an issue first. I imagine that this might not have come up before since the examples in your app don't use the two-letter namespace prefix, which might be messing things up.

Thanks!

Multiple sqlite3 connections

There is only one database connection (named database, ivar in ARDatabaseManager private interface). Is there a possibility to open another connection simultaneously to run queries while the first one let's say is being used for a long-running operation?

Validations firing invalid erros

I've noticed that every time I execute a save or update operation the framework fires all validations, including uniqueness, but the uniqueness validation consider all records that already are on the database including the record which I am updating, so when I update a record and don't change the property with uniqueness validation it will fire a 'already_exists' message.. I thought I could solve it by adding a filter to ignore the record I am editing something like where field = value and id <> this.id where this.id is related to the id of the current record. Unfortunately I couldn't do it by nesting ARWhereStatements, but I think you could. Check this link with my proposal code https://github.com/awleao/iActiveRecord-Uniqueness

nonissue

edit-- sorry, i'm just being stupid

foreign key

I need to set foreign key with relationship,how can i do?

UTF-8 Support on NSString Column

Hi,

Im trying insert this text on database in a NSString column:

@"A História do Coração Selvagem"

But when i read the column from database and show on tableview it show a text with utf8 problem.

I have opened the database with a sqlite client and the text was write correct, so i think that the problem is when i read.

Images are attached.

screen shot 2013-08-06 at 10 10 52 pm

Support for primitive C-style tyles

Hi,

i noticed that there is a support for c-style types (e.g. Properties like BOOL, char, short, double ...etc

Is this true ? Why should i use encapsulated NSNumber types ? Is there a reason why this is not documented up to now ? Otherwise i would like to add some sentences about the possibility to use primitive typed propterties

No distinct ?

The "distinct" statement is missing.
It would be useful to have something like:

 NSArray * distinctRecords= [[[Model LazyFetcher] distinct] fetchRecords];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.